this regular expression

Reply

Join Date: Feb 2008
Posts: 17
Reputation: johndoe444 is an unknown quantity at this point 
Solved Threads: 0
johndoe444 johndoe444 is offline Offline
Newbie Poster

this regular expression

 
0
  #1
30 Days Ago
Why is this regular expression (pat) not working? According to documentation, scan takes both string and regexp.

  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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 44
Reputation: xml_looser is an unknown quantity at this point 
Solved Threads: 2
xml_looser xml_looser is offline Offline
Light Poster
 
0
  #2
30 Days Ago
  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"]]
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 17
Reputation: johndoe444 is an unknown quantity at this point 
Solved Threads: 0
johndoe444 johndoe444 is offline Offline
Newbie Poster
 
0
  #3
30 Days Ago
nice work.

Originally Posted by xml_looser View Post
  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"]]
Reply With Quote Quick reply to this message  
Reply

Message:



Other Threads in the Ruby Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC