Difference between * and + regex

前端 未结 6 1914
你的背包
你的背包 2020-11-22 02:18

Can anybody tell me the difference between the * and + operators in the example below:

[<>]+ [<>]*

6条回答
  •  盖世英雄少女心
    2020-11-22 03:16

    Each of them are quantifiers, the star quantifier(*) means that the preceding expression can match zero or more times it is like {0,} while the plus quantifier(+) indicate that the preceding expression MUST match at least one time or multiple times and it is the same as {1,} .

    So to recap :

    a*  ---> a{0,}  ---> Match a or aa or aaaaa or an empty string
    a+  ---> a{1,}  ---> Match a or aa or aaaa but not a string empty
    

提交回复
热议问题