给定可能的输入字符串“foobar xyz”和“foobar xyz abc def”
如何匹配字符串“foobar-x”(例如“从开始到包括第一个连字符之后的第一个字符”)?
我预料到了 /(.*-.?)(.*)/ 或 /(.*-.{1}?)(.*)/ 但这两个字符都与LAST连字符后的第一个字符匹配。
/(.*-.?)(.*)/
/(.*-.{1}?)(.*)/
用 ? :
?
/(.*?-.?)(.*)/ ^--- here and make it non-greedy