andredms
andredms

Reputation: 157

Lookbehind workaround?

Safari is failing to load my application due to a lookbehind be used (which it does not currently support). Does anyone know a work around for this regex expression?

const regExInclude = /^\s*!(include(?:_many|_once|url|sub)?)\s+((?:(?<=\\)[ ]|[^ ])+)(.*)/;

Thanks!

Upvotes: 0

Views: 104

Answers (1)

The fourth bird
The fourth bird

Reputation: 163362

It seems you only want to match a space when there is a \ directly to the left.

You might write the pattern matching the \ in stead of asserting as well.

Using (?:\\ |\S) you either match a non whitespace char, or only a space preceded by \

^\s*!(include(?:_many|_once|url|sub)?)\s+((?:\\ |\S)+)(.*)

Regex demo

Upvotes: 1

Related Questions