Re: Escaping problem using Regular Expression
From: Martin Marinov (memmarinov_at_mecrossroad.bg)
Date: 07/06/04
- Next message: YuanYuan: "Nice way of eliminating duplicated values in an array?"
- Previous message: Tamir Khason: "Re: listview and progressbar"
- In reply to: Nick Malik: "Re: Escaping problem using Regular Expression"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 6 Jul 2004 09:32:31 +0300
Hi Henry,
in addition of Nick's answer, there is a little modification
@"`~\!@#\$\%\^\&\*\(\)_=\+\[\]\{\}\\\|;:',<\.>/\?" + "\""
Regards
Martin
"Nick Malik" <nickmalik@hotmail.nospam.com> wrote in message
news:OcKFc.21331$Oq2.9279@attbi_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" <ignhenry@hotmail.com> wrote in message
> news:%23aBgmIeXEHA.3016@tk2msftngp13.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.CultureInvariant );
> > 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
> >
> >
>
>
- Next message: YuanYuan: "Nice way of eliminating duplicated values in an array?"
- Previous message: Tamir Khason: "Re: listview and progressbar"
- In reply to: Nick Malik: "Re: Escaping problem using Regular Expression"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|