Regular Expression: +$ VS *$ VS none

后端 未结 4 1179
半阙折子戏
半阙折子戏 2021-02-08 08:54

In regular expressions, what is the difference between ^[a-zA-Z]+$ and ^[a-zA-Z]*$. Also would I be able to not include it at all, either with ^[

4条回答
  •  借酒劲吻你
    2021-02-08 09:45

    ^[a-zA-Z]+$ matches any alphabetic string (consisting of the letters a-z, large or small) of size 1 or longer. The ^ and $ characters mean "start" and "end" of the line, so they only match full lines consisting of one "word".

    ^[a-zA-Z]*S is similar, only the asterisk (*) means "no or any number of" the preceding character/group. The S is just an S and matches exactly one S. Basically the whole thing matches any string that starts at the beginning of a row, contains any number of letters and ends with an S. Other things can come after the S though, the line does not have to end there since $ was not used.

提交回复
热议问题