开发者

Exact match in regex character classes

开发者 https://www.devze.com 2023-02-02 23:30 出处:网络
Consider the following string \'35=_-235-b-35=35-35=2-135=a-35=123-235=2-35=a-53=1-53=a-553=b\' I\'d like to extract everything that matches 35= followed by 1 or 2 characters.

Consider the following string

'35=_-235-b-35=35-35=2-135=a-35=123-235=2-35=a-53=1-53=a-553=b'

I'd like to extract everything that matches 35= followed by 1 or 2 characters. What I came up with is the following regex

\d[35]=[A-Za-z0-9]{1,2}

The problem is the character class [35] matches both 35= and 53=. How can I achieve an exact match for a character class?

Any suggestions, or different approaches are very mu开发者_如何转开发ch appreciated!


Why not just 35 instead of \d[35] ?


to match 35= followed by one or two alphanumeric char you can use

35=\w{1,2}

Felix

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号