Regexp to match a subset of strings but exclude all of a certain character 
Author Message
 Regexp to match a subset of strings but exclude all of a certain character

Hello All,

I am trying to write a regular expression which will match any one of
a subset of strings such as "user unknown|mailbox not found|mailbox
full" but ignore all occurances of a particular character (such as
newline or carriage return) in the source string.

Eg:     strPattern = "([^\n\l]+)user unknown|mailbox not found|mailbox
full"

This will be used to process NDR emails from a bounce mailbox, but
some of the search strings may be not match as the NDR email may be
wrapped by the mail server that sent it, inserting newline/carriage
return characters at the 80-column mark.  If this causes the potential
search string match to be split over two lines the match fails... so I
want to have the regexp ignore all CR/LF characters and basically
treat the whole mail body text (the source string) as one unbroken
line.  I know I could do this in two steps by first doing a replace on
the source string to remove all CR/LF chars then searching the result
for the strings but is there a way to do this in the one regexp?

TIA for your time!

Regards,

Jacob



Sun, 15 Aug 2004 16:02:24 GMT  
 Regexp to match a subset of strings but exclude all of a certain character
well, they should always put the carriage returns at the spaces between the
word, so you should be able to do something like this:
     strPattern = "user\s+unknown|mailbox\s+not\s+found|mailbox\s+full"

where \s is any whitespace character (space, form-feed, etc.)

-K


Quote:
> Hello All,

> I am trying to write a regular expression which will match any one of
> a subset of strings such as "user unknown|mailbox not found|mailbox
> full" but ignore all occurances of a particular character (such as
> newline or carriage return) in the source string.

> Eg:     strPattern = "([^\n\l]+)user unknown|mailbox not found|mailbox
> full"

> This will be used to process NDR emails from a bounce mailbox, but
> some of the search strings may be not match as the NDR email may be
> wrapped by the mail server that sent it, inserting newline/carriage
> return characters at the 80-column mark.  If this causes the potential
> search string match to be split over two lines the match fails... so I
> want to have the regexp ignore all CR/LF characters and basically
> treat the whole mail body text (the source string) as one unbroken
> line.  I know I could do this in two steps by first doing a replace on
> the source string to remove all CR/LF chars then searching the result
> for the strings but is there a way to do this in the one regexp?

> TIA for your time!

> Regards,

> Jacob



Sun, 15 Aug 2004 22:14:31 GMT  
 Regexp to match a subset of strings but exclude all of a certain character
Thanks Kit - prompt reply and spot-on answer!  

Works fine...

Regards,

Jacob

Quote:

> well, they should always put the carriage returns at the spaces between the
> word, so you should be able to do something like this:
>      strPattern = "user\s+unknown|mailbox\s+not\s+found|mailbox\s+full"

> where \s is any whitespace character (space, form-feed, etc.)

> -K



Mon, 16 Aug 2004 08:00:50 GMT  
 Regexp to match a subset of strings but exclude all of a certain character
Glad we could help!


Quote:
> Thanks Kit - prompt reply and spot-on answer!

> Works fine...

> Regards,

> Jacob




Quote:
> > well, they should always put the carriage returns at the spaces between
the
> > word, so you should be able to do something like this:
> >      strPattern = "user\s+unknown|mailbox\s+not\s+found|mailbox\s+full"

> > where \s is any whitespace character (space, form-feed, etc.)

> > -K



Mon, 16 Aug 2004 10:05:35 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. RegExp: how NOT to match string??

2. regexp matches unicode char in string

3. RegExp match of string with square bracket

4. RegExp question: match within another match

5. Extracting A Certain Character From A String

6. Finding if certain characters exist in a string

7. Finding & Counting Certain Characters in a string

8. Checking a String for a Certain Character

9. excluding certain records at runtime

10. Excluding tables with certain attributes

11. RegExp Object and match.value be entire line

12. string pattern matching OR end of string variable

 

 
Powered by phpBB® Forum Software