How do I match these types of strings using and in a regex?

How to do or

and and

together in Regex.

We can do this in a regex (Boo)|(l30o)

and list all the permutations that are basically superior to the purpose of the regex. Here or used.

I want to combine B

in any shape, O

in any shape twice. Something like [(B)|(l3)][0 o O]{2}

. But in this form, it also fits (0O

.

O double match is not a problem.

B when trying to match multiple characters match is a problem along with single character matching.

Should match: Bu b0o l300 I3oO B00

and etc.

All words that look like Boo, i.e. b - {B,b,l3,I3,i3}

and o - {O, o, 0}

;

+3


source to share


3 answers


You can try (?:[bB]|[lIi]3)[0Oo]{2}

:

  • (?:...)

    is not an exciting group
  • [...]

    is a character class, i.e. any character within it (except -

    , depending on the position) is assumed to mean literally (that [iIl]

    corresponds to i

    , L

    or L

    , and [(B)|(l3)]

    will not do what you think it does: it matches any of the (

    , B

    , )

    , |

    , L

    or 3

    ).
  • |

    means "or" and matches whole sequences
  • {...}

    - numeric quantifier (i.e. {2}

    means exactly two times)


You can also use (?i)

at the beginning of your expression to make it case insensitive, i.e. expression will then be (?i)(?:b|[li]3)[0o]{2}

.

+3


source


Can you try the following

(B|b|l3|I3|i3)[0oO]{2}

      



You can try it online at https://regex101.com/r/gLA6N2/3

+2


source


(B|b|l3|I3|i3)(O|o|0)+

      

() - Group

| is or

+ is a quantifier for {1}}, which means 1 or more

+1


source







All Articles