Regular expression greater than and less than

前端 未结 3 1611
遥遥无期
遥遥无期 2021-01-18 09:14

I would like to match any one of these characters: < or > or <= or >= or =.

This one doe

3条回答
  •  清酒与你
    2021-01-18 09:38

    You don't need to escape any of those characters in character class. Apart from that, you need to use quantifiers, to match more than 1 repetition of those characters.

    You need this:

    [<>=]{1,2}
    

    Note the quantifier, to match 2 repetitions, as required for <= and >=.


    Also, note that this will also match - ==, <<. If you strictly want to match just those 4 strings, you can use this regex:

    [<>]=?|=
    

    Using ? after = makes it optional. So, first part will match - <, >, <=, and >=. And then we add = using pipe.

提交回复
热议问题