Dominik
Dominik

Reputation: 117

Exact match in regex character classes

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 much appreciated!

Upvotes: 0

Views: 1147

Answers (2)

Felice Pollano
Felice Pollano

Reputation: 33252

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

35=\w{1,2}

Felix

Upvotes: 1

Nanne
Nanne

Reputation: 64409

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

Upvotes: 3

Related Questions