yayayafi fififi
yayayafi fififi

Reputation: 15

Regex matching digit or specified char

suppose i have this

sdasdas 300 qweqweqwe

I can match it with this regex (\d{2,4}) But how do I match it if one of digits is 'O' not 0 ?(for example 3O0)

Upvotes: 0

Views: 49

Answers (3)

Avinash Raj
Avinash Raj

Reputation: 174874

Just put \d, Uppercase O and lowercase o inside the character class.

[\doO]{2,4}

OR

Use i modifier to turn off the case sensitive mode.

/[\do]{2,4}/i

DEMO

Upvotes: 1

DavidK
DavidK

Reputation: 2564

If you want to match a number with 'o' or 'O'; this will work :

([oO\d]+)

Upvotes: 0

Amal
Amal

Reputation: 76676

Simple enough. Change the character class to include O (both cases) as well:

([\doO]{2,4})

RegEx Demo

Upvotes: 2

Related Questions