我在一些PHP脚本中看到了这个:
[a-zA-Z0-9_]++
双加号代表什么意思?
举个非常简单的例子:
假设你有一个字符串"123"
。在下面的示例中,匹配的字符下方都有一个^
。
Regex: \d+?.
partial match!
123 # The \d+? eats only 1 because he's lazy (on a diet) and leaves the 2 to the .(dot).
^^ # This means \d+? eats as little as possible.
Regex: \d+.
full match!
123 # The \d+ eats 12 and leaves the 3 to the .(dot).
^^^ # This means \d+ is greedy but can still share some of his potential food to his neighbour friends.
Regex: \d++.
no match!
123 # The \d++ eats 123. He would even eat more if there were more numbers following.
# This means \d++ is possessive. There is nothing left over for the .(dot), so the pattern can't be matched.
+
可以像 *
一样用 ?
变成懒惰模式。 - Anoushiravan R