I have this simple code,
string escaped = Regex.Escape( @"`~!@#$%^&*()_ =+[]{}\|;:',<.>/?" + "\"" );
string input = @"a&+[b`${c}a'?sd:r]" + "\"" + @"@(-d)\e";
Regex re = new Regex( string.Format(@ "([{0}]+)", escaped),
RegexOptions.Cu ltureInvariant );
string s = re.Replace( input, "" );
It doesn't seem to work, regular expression return without filter out any
character
However if I remove or change the position of "]" to be the first character,
it works.
string escaped = Regex.Escape( @"]`~!@#$%^&*()_=+[{}\|;:',<.>/?" + "\"" );
I totally do not understand how this regular expression escaping works. What
am I doing wrong here?
Thanks
Henry 2 1631
Hi Henry,
Regular expressions are made up of many of the characters that you placed
into your string. Including the [ and ] characters. The pattern that you
specify has an invalid part [] which is a pattern group where any member can
be matched, but it has no members. that makes the pattern invalid.
Moving the ] to the front of the string means that the regex parser will not
see the bad pattern. However to be truly correct, you still need to quote
any of the characters that can be interpreted as part of a pattern.
@"`~\!@#\$\%\^\ &\*\(\)_=+\[\]\{\}\\|;:',<.>/?" + "\""
Hope this helps,
--- Nick
"Henry" <ig******@hotma il.com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. .. I have this simple code,
string escaped = Regex.Escape( @"`~!@#$%^&*()_ =+[]{}\|;:',<.>/?" + "\"" ); string input = @"a&+[b`${c}a'?sd:r]" + "\"" + @"@(-d)\e"; Regex re = new Regex( string.Format(@ "([{0}]+)", escaped), RegexOptions.Cu ltureInvariant ); string s = re.Replace( input, "" );
It doesn't seem to work, regular expression return without filter out any character However if I remove or change the position of "]" to be the first
character, it works.
string escaped = Regex.Escape( @"]`~!@#$%^&*()_=+[{}\|;:',<.>/?" + "\"" );
I totally do not understand how this regular expression escaping works.
What am I doing wrong here?
Thanks Henry
Hi Henry,
in addition of Nick's answer, there is a little modification
@"`~\!@#\$\%\^\ &\*\(\)_=\+\[\]\{\}\\\|;:',<\. >/\?" + "\""
Regards
Martin
"Nick Malik" <ni*******@hotm ail.nospam.com> wrote in message
news:OcKFc.2133 1$Oq2.9279@attb i_s52... Hi Henry, Regular expressions are made up of many of the characters that you placed into your string. Including the [ and ] characters. The pattern that you specify has an invalid part [] which is a pattern group where any member
can be matched, but it has no members. that makes the pattern invalid.
Moving the ] to the front of the string means that the regex parser will
not see the bad pattern. However to be truly correct, you still need to quote any of the characters that can be interpreted as part of a pattern.
@"`~\!@#\$\%\^\ &\*\(\)_=+\[\]\{\}\\|;:',<.>/?" + "\""
Hope this helps, --- Nick
"Henry" <ig******@hotma il.com> wrote in message news:%2******** ********@tk2msf tngp13.phx.gbl. .. I have this simple code,
string escaped = Regex.Escape( @"`~!@#$%^&*()_ =+[]{}\|;:',<.>/?" +
"\"" ); string input = @"a&+[b`${c}a'?sd:r]" + "\"" + @"@(-d)\e"; Regex re = new Regex( string.Format(@ "([{0}]+)", escaped), RegexOptions.Cu ltureInvariant ); string s = re.Replace( input, "" );
It doesn't seem to work, regular expression return without filter out
any character However if I remove or change the position of "]" to be the first character, it works.
string escaped = Regex.Escape( @"]`~!@#$%^&*()_=+[{}\|;:',<.>/?" +
"\"" ); I totally do not understand how this regular expression escaping works. What am I doing wrong here?
Thanks Henry
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Jane Doe |
last post by:
Hello,
I need to browse a list of hyperlinks, each followed by an
author, and remove the links only for certain authors.
1. I searched the archives on Google, but didn't find how to tell the
RegExp object to be non-greedy as using the ? quantifier doesn't seem
to work.
--------- SAMPLE ----------------
|
by: Henry |
last post by:
I have this simple code,
string escaped = Regex.Escape( @"`~!@#$%^&*()_=+{}\|;:',<.>/?" + "\"" );
string input = @"a&+" + "\"" + @"@(-d)\e";
Regex re = new Regex( string.Format(@"(+)", escaped),
RegexOptions.CultureInvariant );
string s = re.Replace( input, "" );
It doesn't seem to work, regular expression return without filter out any
character
|
by: Buddy |
last post by:
Can someone please show me how to create a regular expression to do the
following
My text is set to
MyColumn{1, 100} Test
I want a regular expression that sets the text to the following
testMyColumn{1, 100}Test
Basically I want the regular expression to add the word test infront of the
|
by: Ryan |
last post by:
HELLO
I am using the following MICROSOFT SUGGESTED (somewhere on msdn)
regular expression to validate email addresses however I understand
that the RFP allows for "+" symbols in the email address and this
method does not....
Does anyone have an explanation?
Function IsValidEmail(ByVal strIn As String) As Boolean
|
by: James D. Marshall |
last post by:
The issue at hand, I believe is my comprehension of using regular
expression, specially to assist in replacing the expression with other text.
using regular expression (\s*) my understanding is that this will one or
more occurrences to replace all the white space between with a comma.
This search
ElseIf InStr(1, indivline, "$") Then
insert a replace statement that uses the regular expression to find and
replace all the white space...
| |
by: gisleyt |
last post by:
I need to escape e.g. & within an attribute, as in:
<foo bar="+$"/>
Since this is a regular expression and will not be validated as a
normal xml file, i cannot use & for &. CDATA does not seem to work
in an attribute either. Any suggestions on how I can get around this?
-Gisle-
|
by: Lubomir |
last post by:
Hi,
I am using the following pattern:
"\\b" + MySttring + "\\b"
If MyString is "one", this should pick up whole words like "one".
The problem is, it will pick up also the word: "one.two" How should I modify
the patter to pickup only "one"?
|
by: Matthew Warren |
last post by:
Hi,
I would expect this to work,
rawstring=r'some things\new things\some other things\'
But it fails as the last backslash escapes the single quote.
...although writing this I think I have solved my own problem. Is \' the
only thing escaped in a raw string so you can place ' in a raw string?
|
by: Allan Ebdrup |
last post by:
I have a dynamic list of regular expressions, the expressions don't change
very often but they can change. And I have a single string that I want to
match the regular expressions against and find the first regular expression
that matches the string.
I've gor the regular expressions ordered so that the highest priority is
first (if two or more regular expressions match the string I want the first
one returned)
The code that does this has...
|
by: Andy B |
last post by:
I need to create a regular expression that will match a 5 digit number, a
space and then anything up to but not including the next closing html tag.
Here is an example:
<startTag>55555 any text</aClosingTag>
I need a Regex that will get all of the text between the html tags above
(the html tags are random and i do not know them before hand). The match
string always starts with at least 5 digits.
|
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...
| |
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,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |