-1

I need to define below regex in Javascript:

(\bin region\b)(?!.*\1).+?(?=<)

I tried like below but it looks like not working:

var reg = new RegExp ('(\bin region\b)(?!.*\1).+?(?=<)');

Although the Atom tool matches the regex in the target string, JavaScript code is returning blank. I am using this in Azure logic app (inline code executor connector) Anyone can help me with this?

You can see it matches the text in Atom:

enter image description here

1 Answers1

1

Inside a string you need to escape the backslashes.

Otherwise the backslash will escape the next character. So, writing \b will escape the character b instead use \\b which will escape the \

var reg = new RegExp ('(\\bin region\\b)(?!.*\\1).+?(?=<)');
Som Shekhar Mukherjee
  • 4,701
  • 1
  • 12
  • 28
  • Thanks @Som for the quick response but it still doesn't work. String is like Error rate is high in application | In Region - ru

    Enrichment Query Details:

    ","RenderType":"Html","Initials":null,"SubmittedByDisplayName":null,"ChangedByDisplayName":null,"IsFromConnector":true}]}} and I am trying to get the 'In Region RU' like text.
    – vivek mishra Apr 03 '21 at 08:59
  • Can you please share the string you are trying to match? @vivekmishra – Som Shekhar Mukherjee Apr 03 '21 at 09:00
  • There might be a problem with how you are using the regex. – Som Shekhar Mukherjee Apr 03 '21 at 09:17