ruby - 什么是 Ruby 正则表达式来匹配至少有一个句点且没有空格的字符串?

标签 ruby regex

匹配至少有一个句点且没有空格的字符串的正则表达式是什么?

最佳答案

你可以使用这个:

/^\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/

相关文章:

javascript - 正则表达式 : Match numbers after specific string

ruby - 我如何在 Ruby 中始终向下舍入数字?

ruby-on-rails - 使用 RABL 和 Draper 渲染 to_json

ruby - RVM:在系统范围安装中从 .rvmrc 文件加载 gemset 时权限被拒绝

regex - 使用正则表达式和排序的 Mongodb 简单前缀查询很慢

java - 使用正则表达式java的字符串操作

Ruby min 函数不选择最短的字符串

ruby - 执行 git 分支策略

javascript - 正则表达式:替换模式内的字符串作为函数的返回值

mysql - 喜欢和正则表达式运算符之间的区别