Home > Enterprise >  regex getting words between '|'
regex getting words between '|'

Time:01-06

I am trying to get the full words between two '|' characters

example string: {{person label|Jens Addle|border=red}}

here I would like to get the string: Jens Addle

I have attempted with the following:

(([A-Z]\w ))

However, this separates the result into two words and I would like to get it as a single entity.

CodePudding user response:

This should put the value into $1.

Key is escaping the pipes, capturing what is in between and being non-greedy about it.

\|(. ?)\|

CodePudding user response:

This should work in your case: /\|(.*?)\|/gm, or without the flags \|(.*?)\|.

This regex matches all character between two | characters. (\| - the | character, (.*?) - match everything and capture)

Here is the regex101 page.

  •  Tags:  
  • Related