473,387 Members | 1,545 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 2395
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: PK9 | last post by:
I'm trying to validate input from a textbox in the code-behind of my page. I don't want to use any validator controls for this, I'd like to do it all in the code behind. However, I'm getting an...
2
by: FrzzMan | last post by:
Hello, Is there any function that automatically escape all regex operator in a string? So that the string that contain regex operator will be identified as a *string*, not a *regex pattern*. ...
2
by: Christopher Ireland | last post by:
Hi -- Any ideas on this one please ... The following code works as expected: private void Form1_Load(object sender, System.EventArgs e) { string text = "The quick brown"+ " FOX " +"jumps over...
3
by: Steve | last post by:
The string in registry is "rundll32.exe C:\Program Files\INTERN~1\hmmapi.dll,OpenInboxHandler" After opensubkey and getregistry, I got "rundll32.exe \"C:\\Program...
2
by: Jeff Jarrell | last post by:
I want to use the regex.replace for a string containing "%s" I can't seem to get the "%s" escaped. I tried a normal "\%s" but that doesn't seem to do it. Picks up any "s"....
4
by: shonend | last post by:
I am trying to extract the pattern like this : "SUB: some text LOT: one-word" Described, "SUB" and "LOT" are key words; I want those words, everything in between and one word following the...
15
by: pkaeowic | last post by:
I am having a problem with the "escape" character \e. This code is in my Windows form KeyPress event. The compiler gives me "unrecognized escape sequence" even though this is documented in MSDN....
6
by: sloan | last post by:
I have a fairly simple RegEx code below. I am given a file name, (which I don't control) , and need to change a folder name in it. The code below is choking on the filename not being...
1
by: =?Utf-8?B?R3VoYW5hdGg=?= | last post by:
I have a string with some escape charaecters that need to be processed in our file Say for example the string might have something like following <escape V=".sp2" /> step 1: This has to be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.