escape a whole regex

T

Tassos

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/;
 
G

Gunnar Hjalmarsson

Tassos said:
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.
 
J

Jim Gibson

Tassos <[email protected]> said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top