本文介绍了正则表达式:如果字符串包含空格则不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我似乎无法找出匹配字符串的正则表达式模式,仅当它不包含空格时.例如
I can't seem to figure out the regex pattern for matching strings only if it doesn't contain whitespace. For example
"this has whitespace".match(/some_pattern/)
应该返回 nil
但是
"nowhitespace".match(/some_pattern/)
应该返回带有整个字符串的 MatchData.任何人都可以为上述问题提出解决方案吗?
should return the MatchData with the entire string. Can anyone suggest a solution for the above?
推荐答案
在 Ruby 中我认为是
In Ruby I think it would be
/^\S*$/
这意味着开始,匹配任意数量的非空白字符,结束"
This means "start, match any number of non-whitespace characters, end"
这篇关于正则表达式:如果字符串包含空格则不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!