| | |
this regular expression
Please support our Ruby advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Feb 2008
Posts: 17
Reputation:
Solved Threads: 0
Why is this regular expression (pat) not working? According to documentation, scan takes both string and regexp.
Thanks.
Ruby Syntax (Toggle Plain Text)
irb(main):001:0> pat = '\d+ (\w+) \(\d+\)' => "\\d+ (\\w+) \\(\\d+\\)" irb(main):002:0> string = 'dfasdf 1 up (2009) sdfasdf 2 walle (2008) adfasdf' => "dfasdf 1 up (2009) sdfasdf 2 walle (2008) adfasdf" irb(main):003:0> string.scan(pat) => []
Thanks.
•
•
Join Date: Apr 2009
Posts: 44
Reputation:
Solved Threads: 2
0
#2 30 Days Ago
Ruby Syntax (Toggle Plain Text)
pat = '(\d+)' string = 'dfasdf 1 up (2009) sdfasdf 2 walle (2008) adfasdf' p string.scan(/#{pat}/) =>[["1"], ["2009"], ["2"], ["2008"]]
•
•
Join Date: Feb 2008
Posts: 17
Reputation:
Solved Threads: 0
0
#3 30 Days Ago
nice work.
•
•
•
•
Ruby Syntax (Toggle Plain Text)
pat = '(\d+)' string = 'dfasdf 1 up (2009) sdfasdf 2 walle (2008) adfasdf' p string.scan(/#{pat}/) =>[["1"], ["2009"], ["2"], ["2008"]]
![]() |
Other Threads in the Ruby Forum
- Previous Thread: Ruby is hot i want to learn it
- Next Thread: problems with ruby dbi
| Thread Tools | Search this Thread |





