For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic > April 2005 > RegEx - select NOT <some string>









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author RegEx - select NOT <some string>
Art

2005-04-27, 8:55 pm

What's the syntax for RegEx to specify that I want to match something that's
NOT a string I specify?
Example: "HELLO WORLD"
RegEx (wanted) = select string that is NOT "WORLD"
Result: "HELLO "


Charlie

2005-04-27, 8:55 pm

Your example looks more like you want to remove a substring from a string
rather than select a string

Result = Replace("HELLO WORLD", "WORLD", "")

Is this what you mean?


"Art" wrote:

> What's the syntax for RegEx to specify that I want to match something that's
> NOT a string I specify?
> Example: "HELLO WORLD"
> RegEx (wanted) = select string that is NOT "WORLD"
> Result: "HELLO "
>
>

Charlie

2005-04-28, 8:55 pm

Sorry I couldn't reply sooner. My IE browser quit displaying the
threads..."error on page" don't know why. I finally loaded FireFox (against
Company rules, but so what)

Without seeing exactly what you are trying to do I'm somewhat at a loss. I
haven't ever used regular expressions. There may be a pattern syntax that
does what you want. I thought somebody else might've replied by now.

How would I do it? The old fashion way... I'd probably break up processing
the string into several steps or loops to remove what I want removed using
the Replace function, or manually, etc. Maybe not slick but if it gets the
job done...who knows maybe I'd get a pay raise! (Yeah, right)


"Art" wrote:
[color=darkred]
> Charlie,
> Unfortunately not. I specifically simplified this regex to make my question
> easily understood. The procesing instructions for the string in question are
> far more complicated and trying to illustrate it w/ concrete regex can be
> difficult to decrypt. So I thought that if I present the opposite then it
> will be easy to understand.
> Basically regex will have to replace all non-alphanumeric characters BUT
> will also have to bypass the patterns which I would specify.
> I know how to negate individual (or set of) characters but how can you
> accomplish the same w/ whole strings?
> For example I can't say regex = [^WORLD] becuse the result is going to be HE
> instead of HELLO. So, how do you negate whole strings instead of individual
> charactes.
> Thanks for you help thou!
>
> "Charlie" wrote:
>
Bonj

2005-04-28, 8:55 pm

Use regex replace - set the regex syntax such that it finds the things you
want to eliminate and replace them with "".

"Art" <Art@discussions.microsoft.com> wrote in message
news:E3D45237-CE29-4C42-B5B6-66591BDA3A4A@microsoft.com...
> What's the syntax for RegEx to specify that I want to match something
> that's
> NOT a string I specify?
> Example: "HELLO WORLD"
> RegEx (wanted) = select string that is NOT "WORLD"
> Result: "HELLO "
>
>



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com