匹配至少有一个句点且没有空格的字符串的正则表达式是什么?
最佳答案
你可以使用这个:
/^\S*\.\S*$/
它是这样工作的:
^ <-- Starts with
\S <-- Any character but white spaces (notice the upper case) (same as [^ \t\r\n])
* <-- Repeated but not mandatory
\. <-- A period
\S <-- Any character but white spaces
* <-- Repeated but not mandatory
$ <-- Ends here
您可以将 \S
替换为 [^ ]
以严格使用空格(而不是制表符等)
关于ruby - 什么是 Ruby 正则表达式来匹配至少有一个句点且没有空格的字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3913436/