sider
sider

Reputation: 687

Regex matching with positive lookhead

I want to match \'' in string Apple MacBook Air 45\'' but my regex does not seem to work:

(?=[0-9]+)(\\'')

How to use possitive lookhead correctly? Or I need something else? I do not want to match using just (\\'') regex.

Upvotes: 0

Views: 62

Answers (1)

Jonny 5
Jonny 5

Reputation: 12389

You need a lookbehind. In most flavors this can only be of fixed width, which should be sufficient:

(?<=[0-9])\\'' or as php pattern: $pattern = "/(?<=[0-9])\\\\''/";

As you just want to check, if there is at least one [0-9] before \''.

See test at regex101.com

Upvotes: 1

Related Questions