Hi,
Quite new to regex myself, Im trying to match a chunk of the text with
the following,
chunk = content.scan(/(.*)/m)
That works alright, and its contents returned to the chunk string. Now
Im trying to do that way,
$start = “”
$end = “”
chunk = content.scan(/$start(.*)$end/m)
Obviously that doesnt works, suppose because of $ being a special
variable ? So my question is how to do pattern matching using variables
like that ?
Thanks !
Rove
···
–
Rove Monteux
Systems Administrator
rove.monteux@fluid-rock.com
— Rove Monteux rove.monteux@fluid-rock.com wrote: > Hi,
Quite new to regex myself, Im trying to match a chunk of the text with
the following,
chunk = content.scan(/(.*)/m)
That works alright, and its contents returned to the chunk string. Now
Im trying to do that way,
$start = “”
$end = “”
chunk = content.scan(/$start(.*)$end/m)
I haven’t tested this, but you are not interpolating the variables
correctly:
chunk = content.scan(/#{$start}(.*)#{$end}/)
Also, unlike Perl, the $ symbol does not denote type, but scope. Do you
really mean for start and end to be globally defined (which is what the $
is implying?).
Hope That Helps,
– Thomas Adam
···
=====
“The Linux Weekend Mechanic” – http://linuxgazette.net
"TAG Editor" – http://linuxgazette.net
" We’ll just save up your sins, Thomas, and punish
you for all of them at once when you get better. The
experience will probably kill you. :)"
– Benjamin A. Okopnik (Linux Gazette Technical Editor)
Yahoo! Messenger - Communicate instantly…"Ping"
your friends today! Download Messenger Now
http://uk.messenger.yahoo.com/download/index.html
Hi,
$start = “”
$end = “”
chunk = content.scan(/$start(.*)$end/m)
Obviously that doesnt works, suppose because of $ being a special
variable ?
Ehm, no, $ in a regexp means itself, or the end if used at
the end of the regexp. $ in a string means just $.
If you want variable replacement, use #{ expression }. Try
this:
chunk = content.scan(/#{start}(.*)#{end}/m)
Kristof
···
On Mon, 26 Apr 2004 20:25:20 +0900, Rove Monteux wrote:
Thats correct ! Im forgetting to interpolate the variable.
Thanks million, yes the variables are read from a xml file and used in
more than one procedure, so yes its global.
Thanks again !
Rove
···
–
Rove Monteux
Systems Administrator
rove.monteux@fluid-rock.com
Thomas Adam wrote:
— Rove Monteux rove.monteux@fluid-rock.com wrote: > Hi,
Quite new to regex myself, Im trying to match a chunk of the text with
the following,
chunk = content.scan(/(.*)/m)
That works alright, and its contents returned to the chunk string. Now
Im trying to do that way,
$start = “”
$end = “”
chunk = content.scan(/$start(.*)$end/m)
I haven’t tested this, but you are not interpolating the variables
correctly:
chunk = content.scan(/#{$start}(.*)#{$end}/)
Also, unlike Perl, the $ symbol does not denote type, but scope. Do you
really mean for start and end to be globally defined (which is what the $
is implying?).
Hope That Helps,
– Thomas Adam
=====
“The Linux Weekend Mechanic” – http://linuxgazette.net
"TAG Editor" – http://linuxgazette.net
" We’ll just save up your sins, Thomas, and punish
you for all of them at once when you get better. The
experience will probably kill you. :)"
– Benjamin A. Okopnik (Linux Gazette Technical Editor)
Yahoo! Messenger - Communicate instantly…"Ping"
your friends today! Download Messenger Now
http://uk.messenger.yahoo.com/download/index.html
Also, if you are using global variables, you can eliminate the brackets.
$start = “”
==>""
$end = “”
==>""
/#$start(.)#$end/
==>/(.)/
···
On Apr 26, 2004, at 4:32 AM, Thomas Adam wrote:
— Rove Monteux rove.monteux@fluid-rock.com wrote: > Hi,
Quite new to regex myself, Im trying to match a chunk of the text with
the following,
chunk = content.scan(/(.*)/m)
That works alright, and its contents returned to the chunk string. Now
Im trying to do that way,
$start = “”
$end = “”
chunk = content.scan(/$start(.*)$end/m)
I haven’t tested this, but you are not interpolating the variables
correctly:
chunk = content.scan(/#{$start}(.*)#{$end}/)