regular expression question 
Author Message
 regular expression question

I want to replace all occurances of "\cf1 " (where "1" could be any integer)
with " " where the expression is not immediately preceded by another "\".
Something akin to this:

mytext = New Regex("[^\\]\\cf[0-9]+ ").Replace(mytext, " ")

Only, I don't want to replace the beginning character [^\\].. I just want to
use it as a matching criteria. How do I do that? I'm hoping to be able to
accomplish this without loops.

Also, why doesn't replacing [0-9]+ in the matching pattern with [:z] work?
According to the docs, "cf[0-9]+" and "cf[:z]" should be equivalant but I
can't seem to get [:z] to work at all.

TIA,
Bob



Wed, 12 Oct 2005 02:08:13 GMT  
 regular expression question
Ok,

If I understand you correctly you just want:
  "\cf1 "    = " "
  "\\cf1 "   = "\\cf1 "

You could do that with:
  regex.replace(input, (?<!\\)\\cf\d+ ", " ")

(?<! <pattern>) tells the RE to not match if the
expression begins with <pattern>.  Look up
  regular expressions, character classes
in MSDN for more grouping constructs.

The [:z] character class is not supported in .NET
languages, just in the Visual Studio Find (using regular
expressions).  Don't ask why they didn't use the same
syntax for both *shrug*.  .Net supports \d as the
equivalent to [0-9].

Quote:
>-----Original Message-----
>I want to replace all occurances of "\cf1 " (where "1"

could be any integer)
Quote:
>with " " where the expression is not immediately preceded
by another "\".
>Something akin to this:

>mytext = New Regex("[^\\]\\cf[0-9]+ ").Replace
(mytext, " ")

>Only, I don't want to replace the beginning character

[^\\].. I just want to
Quote:
>use it as a matching criteria. How do I do that? I'm

hoping to be able to
Quote:
>accomplish this without loops.

>Also, why doesn't replacing [0-9]+ in the matching

pattern with [:z] work?
Quote:
>According to the docs, "cf[0-9]+" and "cf[:z]" should be
equivalant but I
>can't seem to get [:z] to work at all.

>TIA,
>Bob

>.



Wed, 12 Oct 2005 02:47:47 GMT  
 regular expression question
Oh, yeah. More info about why I'm asking this question... I thought I had
found a solution, here's what the docs say:

Prevent match
~(X)
Prevents a match when X appears at this point in the expression. For
example, real~(ity) matches the "real" in "realty" and "really," but not the
"real" in "reality."

Only the example provided doesn't work at all, and neither do any of my own
attempts to use ~().

I hope someone can tell me why. Maybe I'm just being braindead today.

TIA,
Bob


Quote:
> I want to replace all occurances of "\cf1 " (where "1" could be any
integer)
> with " " where the expression is not immediately preceded by another "\".
> Something akin to this:

> mytext = New Regex("[^\\]\\cf[0-9]+ ").Replace(mytext, " ")

> Only, I don't want to replace the beginning character [^\\].. I just want
to
> use it as a matching criteria. How do I do that? I'm hoping to be able to
> accomplish this without loops.

> Also, why doesn't replacing [0-9]+ in the matching pattern with [:z] work?
> According to the docs, "cf[0-9]+" and "cf[:z]" should be equivalant but I
> can't seem to get [:z] to work at all.

> TIA,
> Bob



Wed, 12 Oct 2005 02:48:16 GMT  
 regular expression question
Thank you, works great.

I should have guessed that since that help doc page I was looking at was so
easy to use to look up usage, naturally they would find a way to make it
useless and instead make me look for answers scattered around multiple pages
with titles that don't make any sense to a layman. Silly me! (slaps hand on
forehead)

Bob


Quote:
> Ok,

> If I understand you correctly you just want:
>   "\cf1 "    = " "
>   "\\cf1 "   = "\\cf1 "

> You could do that with:
>   regex.replace(input, (?<!\\)\\cf\d+ ", " ")

> (?<! <pattern>) tells the RE to not match if the
> expression begins with <pattern>.  Look up
>   regular expressions, character classes
> in MSDN for more grouping constructs.

> The [:z] character class is not supported in .NET
> languages, just in the Visual Studio Find (using regular
> expressions).  Don't ask why they didn't use the same
> syntax for both *shrug*.  .Net supports \d as the
> equivalent to [0-9].

> >-----Original Message-----
> >I want to replace all occurances of "\cf1 " (where "1"
> could be any integer)
> >with " " where the expression is not immediately preceded
> by another "\".
> >Something akin to this:

> >mytext = New Regex("[^\\]\\cf[0-9]+ ").Replace
> (mytext, " ")

> >Only, I don't want to replace the beginning character
> [^\\].. I just want to
> >use it as a matching criteria. How do I do that? I'm
> hoping to be able to
> >accomplish this without loops.

> >Also, why doesn't replacing [0-9]+ in the matching
> pattern with [:z] work?
> >According to the docs, "cf[0-9]+" and "cf[:z]" should be
> equivalant but I
> >can't seem to get [:z] to work at all.

> >TIA,
> >Bob

> >.



Wed, 12 Oct 2005 03:11:54 GMT  
 regular expression question
I have had the same problem with the C# documentation in .NET. It
clearly states "real~(ity)" matches "real" in "really" but not in
"reality"... and then you discover that the example doesn't work!

I built the regular expression "real(?!ity)", this matches the "real"
in "really" but does not match the "real" in "really".

I'm unsure as to where the documented example came from (and to be
honest I'm not sure how the above example works, as the syntax is
undescribed), but this works now.

Hope that's some help.

Chris Fox

Quote:

> Oh, yeah. More info about why I'm asking this question... I thought I had
> found a solution, here's what the docs say:

> Prevent match
> ~(X)
> Prevents a match when X appears at this point in the expression. For
> example, real~(ity) matches the "real" in "realty" and "really," but not the
> "real" in "reality."

> Only the example provided doesn't work at all, and neither do any of my own
> attempts to use ~().

> I hope someone can tell me why. Maybe I'm just being braindead today.

> TIA,
> Bob



> > I want to replace all occurances of "\cf1 " (where "1" could be any
>  integer)
> > with " " where the expression is not immediately preceded by another "\".
> > Something akin to this:

> > mytext = New Regex("[^\\]\\cf[0-9]+ ").Replace(mytext, " ")

> > Only, I don't want to replace the beginning character [^\\].. I just want
>  to
> > use it as a matching criteria. How do I do that? I'm hoping to be able to
> > accomplish this without loops.

> > Also, why doesn't replacing [0-9]+ in the matching pattern with [:z] work?
> > According to the docs, "cf[0-9]+" and "cf[:z]" should be equivalant but I
> > can't seem to get [:z] to work at all.

> > TIA,
> > Bob



Tue, 18 Oct 2005 22:05:30 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Regular Expression Question

2. Rather simple regular expression question....

3. Regular expressions questions

4. complex regular expression question

5. Regular Expression question

6. Regular Expression question

7. Regular expression question

8. Regular Expressions Question

9. Regular Expressions Question

10. Regular expressions question

11. Regular Expressions question

12. regular expression question

 

 
Powered by phpBB® Forum Software