Does the quantifier {0} make sense in some scenarios?

前端 未结 4 1609
无人共我
无人共我 2020-12-30 08:14

Example:

/(?:Foo){0}bar/

I saw something like this in another answer. At first I thought \"what should that be\", but then, \"OK could make sense, kind of a

4条回答
  •  没有蜡笔的小新
    2020-12-30 08:51

    In traditional regular expressions, /x{0}/ (language = { xn : x = 0}) would mean "match exactly 0 of x", which is the same thing as // (language = { Λ }). Since the two are equivalent, you should be able to remove any /x{0}/ you find lying around.

    But PCREs and other extensions to regular expressions can get quite byzantine. I would not be surprised if /x{0}/ did something in Perl. I would be disgusted, but not surprised.

    I think it's probably some artifact of a program that automatically generates regular expressions but doesn't simplify them. Which is a shame, since it's so easy to write programs that simplify regular expressions.

提交回复
热议问题