What's the difference between () and [] in regular expression patterns?

后端 未结 6 2025
梦谈多话
梦谈多话 2020-12-01 00:57

What is the difference between encasing part of a regular expression in () (parentheses) and doing it in [] (square brackets)?

How does this:

[a-z0         


        
6条回答
  •  -上瘾入骨i
    2020-12-01 01:24

    [a-z0-9] will match any lowercase letter or number. (a-z0-9) will match the exact string "a-z0-9" and allows two additional things: You can apply modifiers like * and ? and + to the whole group, and you can reference this match after the match with $1 or \1. Not useful with your example, though.

提交回复
热议问题