473,594 Members | 2,747 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2403
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.256 610@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
8270
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 "unrecognized escape sequence" compile error. Can someone please help me determine the correct regular expression statement? I'm trying to validate that the textbox only contains "Safe" characters (digits, letters, spaces, periods, etc). Here...
2
1689
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*. If there's no function like that, if you have time and it is not so complex, can you help me code one? Thanks.
2
19838
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 the lazy dog."; string pattern = "FOX"; string replacement = "cat";
3
2604
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 Files\\INTERN~1\\hmmapi.dll\",OpenInboxHandler" Is there anyway I can get the string exactly in registry without escape character?
2
1306
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". --------------------------------------------------------------------- Dim options As RegexOptions = RegexOptions.None Dim oRegex As Regex = New Regex("", options) dim s as string
4
3597
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 "LOT:". Source text may contain multiple "SUB: ... LOT:" blocks. For example this is my source text:
15
18305
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. Any idea if this is a bug? if (e.KeyChar == '\e') { this.Close(); }
6
6293
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 escaped. "Unrecognized escape sequence"
1
1871
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 replaced to "escape V=".sp2" step 2: Later it has to be reversed as original(<escape V=".sp2" />) after some processing.
0
7941
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7874
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8368
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8231
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6652
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5404
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3854
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3895
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1476
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.