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.
我正在寻找一种方法来匹配除“#”之外的任何字符。
它看起来像......
gsub(/^foo.*foo$/)
但我希望它匹配
"foofdfdfdfoo"
但不是
"fooddgdgd#fdfoo"
谢谢。
^[^#]+$
http://rubular.com/r/glijo99dU9
gsub是为了替代。如果你只想匹配,.match方法
gsub
.match
为了扩展 Explosion Pills 答案,插入符号 (^) 将否定正则表达式中的匹配。这意味着如果在表达式中找到它后面的字符,它将不匹配。您可以在文档中阅读有关它的更多信息。