-1

Is there any way to select a string after a specified word?

I found many examples how to select with classic regex:

(?<=^License:\W)(\w.*)$

...but JS regex is not supporting positive look behind.

I would like to match string after word "License:":

License: 1234-YXCMD-12XMDM-XXXCC

Is there any solution? I would like to use it on http://integromat.com, which supports only JS regex format.

Adrian
  • 2,576
  • 9
  • 49
  • 97

1 Answers1

1

Here's a good doc from MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Assertions#Types

So here's something you can do:

let str = "License: 1234-YXCMD-12XMDM-XXXCC"
let regexp = /(?<=License: ).*/
console.log(str.match(regexp)[0]) // get 1234-YXCMD-12XMDM-XXXCC

EDIT: This only works in the newest version of Google Chrome as pointed out by @the fourth bird

Thomas Bui
  • 188
  • 3
  • 10
  • `...but JS regex is not supporting positive look behind.` Your pattern uses a positive lookbehind. – The fourth bird Oct 02 '19 at 06:58
  • 1
    @Thefourthbird that's why I have the links there to prove that JS actually support positive look behind – Thomas Bui Oct 03 '19 at 15:45
  • Lookbehinds are not widely supported in Javascript, see for example [this page](https://stackoverflow.com/questions/30118815/why-are-lookbehind-assertions-not-supported-in-javascript) and [this page](https://stackoverflow.com/questions/641407/javascript-negative-lookbehind-equivalent) But as the OP mentioned that it did not work your suggestion will not help solving the problem as it contains a positive lookbehind. – The fourth bird Oct 04 '19 at 08:16
  • Yup, you are right. I tried the above regex using Firefox and it did not work. Seems like only the newest version of Chrome supports it. I forgot that the '^' meant at the beginning so I thought they were using a different regexp' – Thomas Bui Oct 04 '19 at 21:23