944,035 Members | Top Members by Rank

Ad:
  • Ruby Discussion Thread
  • Unsolved
  • Views: 1905
  • Ruby RSS
Oct 29th, 2009
0

this regular expression

Expand Post »
Why is this regular expression (pat) not working? According to documentation, scan takes both string and regexp.

Ruby Syntax (Toggle Plain Text)
  1. irb(main):001:0> pat = '\d+ (\w+) \(\d+\)'
  2. => "\\d+ (\\w+) \\(\\d+\\)"
  3. irb(main):002:0> string = 'dfasdf 1 up (2009) sdfasdf 2 walle (2008) adfasdf'
  4. => "dfasdf 1 up (2009) sdfasdf 2 walle (2008) adfasdf"
  5. irb(main):003:0> string.scan(pat)
  6. => []

Thanks.
Reputation Points: 11
Solved Threads: 0
Posting Whiz in Training
johndoe444 is offline Offline
214 posts
since Feb 2008
Oct 29th, 2009
0
Re: this regular expression
Ruby Syntax (Toggle Plain Text)
  1.  
  2. pat = '(\d+)'
  3. string = 'dfasdf 1 up (2009) sdfasdf 2 walle (2008) adfasdf'
  4. p string.scan(/#{pat}/)
  5. =>[["1"], ["2009"], ["2"], ["2008"]]
Reputation Points: 16
Solved Threads: 21
Junior Poster
xml_looser is offline Offline
178 posts
since Apr 2009
Oct 29th, 2009
0
Re: this regular expression
nice work.

Click to Expand / Collapse  Quote originally posted by xml_looser ...
Ruby Syntax (Toggle Plain Text)
  1.  
  2. pat = '(\d+)'
  3. string = 'dfasdf 1 up (2009) sdfasdf 2 walle (2008) adfasdf'
  4. p string.scan(/#{pat}/)
  5. =>[["1"], ["2009"], ["2"], ["2008"]]
Reputation Points: 11
Solved Threads: 0
Posting Whiz in Training
johndoe444 is offline Offline
214 posts
since Feb 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Ruby Forum Timeline: Ruby is hot i want to learn it
Next Thread in Ruby Forum Timeline: problems with ruby dbi





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC