I read some tutorials about regex and I saw a sentence:
(?<=exp): Match any position following a prefix exp
For example, I have some strings:
Share
Care
If I want to find all string include "are", but "are" must follow "Sh": /(?<=Sh)are/i. Now only "Share" is matched, and matched index is 2 (match "are", not "Share" from "Share").
But Javascript don’t have this regex. How can I do like that in Javascript?
Thanks!
You can’t do it. There are no lookbehind assertions in Javascript’s implementation of regular expressions.
Alternatives
In some situations you can instead use a grouping to capture what you actually wanted to match:
/Sh(are)/iIf you really need lookbehinds you could use a third-party regular expression library.
Related