Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
这是我的模式:
^~[0-9]+@Y 1,710,-?[0-9]+[,-?[0-9]+]*\n$
出于某种原因,它是匹配的:~01@Y 1,710,9,
~01@Y 1,710,9,
但不是:~01@Y 1,710,9
~01@Y 1,710,9
我不明白为什么它需要最后一个逗号?
http://regex101.com/r/kP4pZ2/1
我认为这里的问题是
[,-?[0-9]+]*
它将匹配"~01@Y 1,710,9,"或"~01@Y 1,710,[9]"
"~01@Y 1,710,9,"
"~01@Y 1,710,[9]"
如果你只想用逗号、问号、数字或“-”来定义你的表达式匹配,你可以试试下面的表达式:
^~[0-9]+@Y 1,710,-?[0-9]+[,?0-9-]*$