regex

find a substring with regex


I'm trying to find how to match regex for the following string "Myanmar | Yangon-Taunggyi | Search | Worldwide | EN"

I need to extract "Yangon-Taunggyi" so my question is how can I find with regex "Myanmar |" and "| Search | Worldwide | EN"

in general i need the second text between the |


Solution

  • (?<=Myanmar\s\|\s).*(?=\s\|\sSearch)
    

    This pattern will do the job.

    You can see how this works here