nokogiri - Why is this generated ruby regex not working in the actual code? -
i found site can generate ruby regex. enter text , click part want extract:

so tried it:
product.css('.cravgstars .swsprite span').text[/([+-]?\\d*\\.\\d+)(?![-+0-9\\.])/, 1] to 4.4 got nil instead.
is regex not working or placed in incorrect way?
try this:
s = "4.4 out of 5 stars" p s[/([+-]?\d*\.\d+)(?![-+0-9\.])/] # >> "4.4" you can find wayregexp.new:
regexp.new('([+-]?\\d*\\.\\d+)(?![-+0-9\\.])') # => /([+-]?\d*\.\d+)(?![-+0-9\.])/
Comments
Post a Comment