469,917 Members | 1,925 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,917 developers. It's quick & easy.

escape a whole regex

I have a file with 2 fields (";" is the seperator): 1 string (field1) & 1 regex (field2)

test1;([\w\-\.:/]+)
test2;(\w\d [\d\/]+)
test3;([\w\d\.])

I want while reading the file to have an array being filled with field1 kai another array
being filled with field2 (easy until here). But field2 should be escaped (all possible
metacharacters) because it will be used as a regex.

e.x.
my $temp =~ s/$field1/$field2/;

Jul 19 '05 #1
2 2319
Tassos wrote:
I have a file with 2 fields (";" is the seperator): 1 string
(field1) & 1 regex (field2)

test1;([\w\-\.:/]+)
test2;(\w\d [\d\/]+)
test3;([\w\d\.])

I want while reading the file to have an array being filled with
field1 kai another array being filled with field2 (easy until
here).
Good. :)
But field2 should be escaped (all possible metacharacters) because
it will be used as a regex.

e.x.
my $temp =~ s/$field1/$field2/;


What you are saying here does not make sense. Please show us the code
you have written so far, illustrating the problem you encounter.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Jul 19 '05 #2
In article <1071247180.256610@athprx02>, Tassos <ch******@yahoo.com>
wrote:
I have a file with 2 fields (";" is the seperator): 1 string (field1) & 1
regex (field2)

test1;([\w\-\.:/]+)
test2;(\w\d [\d\/]+)
test3;([\w\d\.])

I want while reading the file to have an array being filled with field1 kai
another array
being filled with field2 (easy until here). But field2 should be escaped (all
possible
metacharacters) because it will be used as a regex.

e.x.
my $temp =~ s/$field1/$field2/;


This newsgroup is defunct. Please do not start threads here. Try
comp.lang.perl.misc in the future for better response.

It is best to attempt to write a program to do what you are trying and
then post it if it doesn't work. Check out the quote regex operator
qr//. It should help you do what you want.
Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by FrzzMan | last post: by
2 posts views Thread by Christopher Ireland | last post: by
3 posts views Thread by Steve | last post: by
2 posts views Thread by Jeff Jarrell | last post: by
15 posts views Thread by pkaeowic | last post: by
1 post views Thread by =?Utf-8?B?R3VoYW5hdGg=?= | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.