From: Jet Koten Date: 2010-02-27T08:23:31+09:00 Subject: Re: Regex for "not matching" an unneeded prefix substring? Robert Klemme wrote: > 2010/2/26 Jet Koten : >> �condition = item.search(".condition").text.match(/Used - ([^,]+)/) >> "Used - Very Good" >> >> The regex that I've got there in the condition line works in Rubular, >> but not in my code. I'm running 1.8.7 if that matters... > > I am not sure which regexp you are referring to specifically. > However, you can do this > > irb(main):001:0> s = "Used - Like New" > => "Used - Like New" > irb(main):002:0> s[/\AUsed\s+-\s+(.*)\z/, 1] > => "Like New" > irb(main):003:0> s[7..-1] > => "Like New" > > String#[] with regular expression is a very powerful tool - especially > when used with grouping as in this case. > >> One last thing that I don't understand too is that in Rubular my regex >> for price shows the match in the "Match result:" line, but the regex for >> condition shows the whole string as a match in the "Match result:" line >> but shows the correctlt matching substring in the "Match captures:" >> line. > > I am having difficulties to follow you here since I don't know what > "item" is in your case. It's probably easier if you provide a simple > test case that demonstrates your point. Using IRB often also helps. > >> I'm grateful for this great resource (the list/forum) and would be very >> happy to hear from anyone who can help me sort this out! > > We'll try to help but please provide a bit more information. > > Kind regards > > robert Hi Robert, Thanks a lot. I've discovered that there are many ways of achieving this goal, whether it's through regex, ranges, or even split (as a friend offline just advised me of). I've gotten it working for now, but I'll likely be back eventually when the next question arises. :) -- Posted via http://www.ruby-forum.com/.