Hi, I’m trying to write a regular expression to match a quotation mark
inside a string. Actually, what I want is to extract the text between two
quotation marks, like this:
This should be “simple”, but I can’t do it.
I want to extract the word simple with a regular expression.
Thanks a lot!
···
–
“If it was so, it might be; and if it were so, it would be; but as it isn’t,
it ain’t. That’s logic” – Lewis Carroll
Hi, I’m trying to write a regular expression to match a quotation mark
inside a string. Actually, what I want is to extract the text between
two quotation marks, like this:
This should be “simple”, but I can’t do it.
I want to extract the word simple with a regular expression.
if /“([^”]*)/ =~ ‘This should be “simple”, but I can't do it.’
puts $1
end
I would recommend Mastering Regular Expressions by Jeff Friedl, from
Oreily.
Hope that helps,
Walt
···
Walter Szewelanczyk
IS Director
M.W. Sewall & CO. email : walter@mwsewall.com
259 Front St. Phone : (207) 442-7994 x 128
Bath, ME 04530 Fax : (207) 443-6284
Hi, I’m trying to write a regular expression to match a quotation mark
inside a string. Actually, what I want is to extract the text between two
quotation marks, like this:
This should be “simple”, but I can’t do it.
I want to extract the word simple with a regular expression.
Thanks a lot!
should fit:
rgx=/“([^”]+)/
=> /“([^”]+)/
m= rgx.match ‘this is my “simple” sting’
=> #MatchData:0x27c5760
m[1]
=> “simple”
read like:
match a " and then read any charcater while it is not a "
not that it does not handle escaped "
···
il Fri, 26 Mar 2004 13:15:13 +0100, “Einar Buffer” _ebuffer_@hotmail.com ha scritto::
Hi, I’m trying to write a regular expression to match a quotation mark
inside a string. Actually, what I want is to extract the text between
two
quotation marks, like this:
This should be “simple”, but I can’t do it.
I want to extract the word simple with a regular expression.
Thanks a lot!
should fit:
rgx=/“([^”]+)/
=> /“([^”]+)/
m= rgx.match ‘this is my “simple” sting’
=> #MatchData:0x27c5760
m[1]
=> “simple”
read like:
match a " and then read any charcater while it is not a "
Hi, I’m trying to write a regular expression to match a quotation mark
inside a string. Actually, what I want is to extract the text between
two
quotation marks, like this:
This should be “simple”, but I can’t do it.
I want to extract the word simple with a regular expression.
Thanks a lot!
should fit:
rgx=/“([^”]+)/
=> /“([^”]+)/
m= rgx.match ‘this is my “simple” sting’
=> #MatchData:0x27c5760
m[1]
=> “simple”
read like:
match a " and then read any charcater while it is not a "
if tokens
tokens << token
else
yield token, index
index += 1
end
end
tokens
end
end # module Scanner
Hi, thank you very much for your informative replies! In addition to being
very new to ruby and not really experienced with regular expressions in
general, it turns out I was also confused by the editor I’ve been using for
my first few ruby scripts - SciTE seems to be confused by regular
expressions, and so led me to believe that something was wrong with my
regular expression while in reality it was perfectly legal…
Many regards,
Einar
···
il Fri, 26 Mar 2004 13:15:13 +0100, “Einar Buffer” > > _ebuffer_@hotmail.com ha scritto::