Regex Problem

Hello all,

I am trying to match this pattern: >1_9_1912_F3

Here is my stab at it:
if f3_entry =~ /(>*\_*\_*\_F3)/
  f3_out.puts f3_entry
end

Obviously, it doesn't work. I need to match whatever is between those
underscores. Am i going in the right direction? Thanks in advance!

- C

···

--
Posted via http://www.ruby-forum.com/.

Check out rubular.com where you can interactively match text with your regular expression. This will help you confirm when you're on the right track.

···

From my iPhone
---
Pat

On Sep 9, 2011, at 8:02 AM, "Cyril J." <cyril.varghese.jose@gmail.com> wrote:

Hello all,

I am trying to match this pattern: >1_9_1912_F3

Here is my stab at it:
if f3_entry =~ /(>*\_*\_*\_F3)/
f3_out.puts f3_entry
end

Obviously, it doesn't work. I need to match whatever is between those
underscores. Am i going in the right direction? Thanks in advance!

- C

--
Posted via http://www.ruby-forum.com/\.

I am trying to match this pattern: >1_9_1912_F3

Here is my stab at it:
if f3_entry =~ /(>*\_*\_*\_F3)/
  f3_out.puts f3_entry
end

Obviously, it doesn't work. I need to match whatever is between those
underscores. Am i going in the right direction? Thanks in advance!

If that's all you need then I'd just use split and call it a day:
irb(main):001:0> "1_9_1912_F3".split(/_/)=> ["1", "9", "1912", "F3"]
Regards,Chris WhiteTwitter: http://www.twitter.com/cwgem

Thanks Pat rubular helped a lot.
I used :

([0-9]*[_][0-9]*[_][0-9]*[_])

I probably wasn't too clear with what I wanted earlier, so I apologize
for that. Thanks for the help.

···

--
Posted via http://www.ruby-forum.com/.

Equivalent: /(\d*_\d*_\d*_)/

Or even: /((?:\d*_){3})/

···

On Sep 9, 2011, at 9:25 AM, "Cyril J." <cyril.varghese.jose@gmail.com> wrote:

Thanks Pat rubular helped a lot.
I used :

([0-9]*[_][0-9]*[_][0-9]*[_])

[0-9] is the same as \d:

and * means 0 or more, which I'm not sure it's really what you need. If you
don't want to check for a specific number of digits but need 1 or more use +

/>\d+_\d+_\d+_F3/

If you want to limit to specific number of digits, you can use {a} to
specify a range of numbers (or range of numbers), or no quantifier it it's
exactly one occurence. For example:

/>\d_\d_\d{4}_F3/

which means, match >, then a digit, then _, then another digit, then another
_, then 4 digits, then _F3

Jesus.

···

El 09/09/2011 17:26, "Cyril J." <cyril.varghese.jose@gmail.com> escribió:

Thanks Pat rubular helped a lot.
I used :

([0-9]*[_][0-9]*[_][0-9]*[_])

I probably wasn't too clear with what I wanted earlier, so I apologize
for that. Thanks for the help.

Cyril, are you sure you want to also match "___"? If not, use

/(?:\d+_){3}F3/

Kind regards

robert

···

On Fri, Sep 9, 2011 at 9:39 PM, Gavin Kistner <phrogz@me.com> wrote:

On Sep 9, 2011, at 9:25 AM, "Cyril J." <cyril.varghese.jose@gmail.com> wrote:

Thanks Pat rubular helped a lot.
I used :

([0-9]*[_][0-9]*[_][0-9]*[_])

Equivalent: /(\d*_\d*_\d*_)/

Or even: /((?:\d*_){3})/

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/