Regular expression to match a word or its prefix

后端 未结 4 786
盖世英雄少女心
盖世英雄少女心 2020-12-07 13:33

I want to match a regular expression on a whole word.

In the following example I am trying to match s or season but what I have matches

4条回答
  •  不思量自难忘°
    2020-12-07 14:11

    [ ] defines a character class. So every character you set there, will match. [012] will match 0 or 1 or 2 and [0-2] behaves the same.

    What you want is groupings to define a or-statement. Use (s|season) for your issue.

    Btw. you have to watch out. Metacharacters in normal regex (or inside a grouping) are different from character class. A character class is like a sub-language. [$A] will only match $ or A, nothing else. No escaping here for the dollar.

提交回复
热议问题