0

I am trying to write a regular expression which gives me words which starts with <!= and ends with =>. For example if there is a sentence what is your <!=name=>, the result should give me name because it matches my pattern.

I have read to use this ^ for starts with and $ for ends with, but I am not able to match a combination of special characters.

gaurav tiwari
  • 1,093
  • 1
  • 9
  • 28
  • usually you can use `\b` for word boundaries. So you should use `\bXY\w+` where XY is your character combination – gaw Oct 18 '18 at 12:24
  • then you should use `<!=\b(\w+)=>` or you can even remove the `\b` since the special characters are not part of the word-charcter class. Have a look at: https://regex101.com/r/qDrobh/3 – gaw Oct 18 '18 at 12:28

1 Answers1

0

As in the comment. You can use <!=(\w+)=> because the exclamation mark and equal sign are not part of word-character class you can simply test for those characters and match the word characters between them. check:https://regex101.com/r/qDrobh/4

For multiple words you can use:<!=((?:\w+| )*)=> See:https://regex101.com/r/qDrobh/5

gaw
  • 1,960
  • 2
  • 14
  • 18