Ruby regexp标志x对我不起作用
我的正则表达式怎么了Ruby regexp标志x对我不起作用,ruby,regex,Ruby,Regex,我的正则表达式怎么了 DATE_REGEX = /\d{1,2}\/\d{1,2}\/\d{4}/ def x_flag_testing str = "Service Date: 2/5/2016 to 15/6/2016" regex = /service date:\s+ (?<start_date>#{DATE_REGEX})\s+to\s+ (?<end_date>#{DATE_REGEX})/ix bindin
DATE_REGEX = /\d{1,2}\/\d{1,2}\/\d{4}/
def x_flag_testing
str = "Service Date: 2/5/2016 to 15/6/2016"
regex = /service date:\s+
(?<start_date>#{DATE_REGEX})\s+to\s+
(?<end_date>#{DATE_REGEX})/ix
binding.pry
puts str[regex, :start_date]
end
我正试图:
结果是零!
要显示我的正则表达式在一行中运行良好且没有x标志,请执行以下操作:
可能是因为x标志忽略了服务和日期之间的文字空间 将其更改为\s+:
1.请将代码粘贴为纯文本。2.请分享日期。
/service\s+date:\s+.../ix