2

I am looking for regex lookbehind alternative because autodl-irssi doesnt support it.

Here is my current working regex and test string:

https://regex101.com/r/Cg6mPv/1

I think that regex needs the following replacement (mode modifier and positive lookbehind):

(?i)(?<=\s|^|\W)

Highlights every line containing any of these words (no case sensitive):

*update*
*dlc*
*expansion*
*artwork*
*fix*
*keygen*
*goodies*
*guide*
*trainer*

Doesnt highlight if line containts a word (no case sensitive):

*fitgirl*

Appreciate any help!

Dominik
  • 121
  • 9
  • 1
    Your pattern is not well-written and thus is not clear. However, it seems like you want to match a word boundary before a word char, so you can replace `(?<=\s|^|\W)` with `\b(?=\w)`. – Wiktor Stribiżew Jun 16 '21 at 17:32
  • @WiktorStribiżew Thanks for the quick answer, I think it works flawlessly! – Dominik Jun 16 '21 at 18:12
  • 1
    If you have further issues with the pattern, please edit the question and let me know via a comment below the answer. – Wiktor Stribiżew Jun 16 '21 at 18:27

1 Answers1

1

The (?<=\s|^|\W) pattern is basically equal to (?<=^|\W) or (?<!\w), a place in string that is either the string start position, or a location immediately preceded with a non-word char (i.e. a char other than a letter, digit or _).

Thus, it makes sense to match a word boundary position that is followed by a word char instead:

\b(?=\w)

This construct is equal to \m or [[:<:]] leading word boundary constructs that are supported by some (not many) regex flavors and just require a word char to appear immediately to the right of them.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563