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:

enter image description here

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

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -