I'm using Prism.js which is syntax highlighter, and it highlights the word matching certain regex.
I want to match any word after the word git
, so I tried to use positive lookbehind like this.
(?<=git )\w+
Unfortunately, it seems that positive lookbehind is not supported, so I have to find a equivalent regex expression of it. Is there any way to match any word after the word git
without using positive lookbehind?
For example, I want to do this without positive lookbehind.
"git checkout master" -> only "checkout"
"git log --graph" -> only "log"
"anything after the word git matches" -> only "matches"
Also, I cannot use group because I can't tell Prism to choose certain group. It will always highlight the whole match.
For example, (?:git )(\w+)
will save any word after the word git
in the first group, but it matches the word git and the word after git. So it will highlight
"git checkout master" -> "git checkout"
"git log --graph" -> "git log"
"anything after the word git matches" -> "git matches"
and this is not what I want.
As rightfully mentioned in the comments by @WiktorStribiżew "if you can't access a group and have no lookaround features, or \K operator, you can't do what you need." Generally speaking that would be the case, however, without knowing too much about Prism
a search throught it's documentation brought me to this, which at the lookbehind
option section states:
"'lookbehind' : This option mitigates JavaScript’s lack of lookbehind. When set to true, the first capturing group in the regex pattern is discarded when matching this token, so it effectively behaves as if it was lookbehind."
The above should mean that you could try a pattern like: (\bgit )\w+
when you have set lookbehind: true
.