Topic: Match a line

THis is probably a no brainer, but I can't seem to figure it out

What would be the best way to match something in between tags, say if I had this:

i*this is some text*i

I'd want to match everything between the i* *i tags. What would be the best way to regex that so that I can return the value in between them?

Thanks!

Last edited by RailsRhino (2011-02-14 01:27:24)

- Ben

Re: Match a line

chaine = "i*dcjndlkjn*i"
if chaine =~/^i\*.+\*i$/
  puts "matched"
else
  puts "no matches"
end

Re: Match a line

Thanks Javix, but that only matches assuming the line begins and ends with i* *i. But it could be like this too:

some text *isomei* text

- Ben

Re: Match a line

irb(main):001:0> s = "some text *isomei* text"
=> "some text *isomei* text"
irb(main):002:0> s =~ /\*i(.+)i\*/
=> 10
irb(main):003:0> $1
=> "some"
irb(main):004:0>

This will get a little more complex if you want to cover strings containing multiple *i..i*'s

Re: Match a line

Thanks I appreciate it

- Ben