Regexp char class: mixing ranges and negation? 
Author Message
 Regexp char class: mixing ranges and negation?

I'm lazy. I want a regular expression that will match all visible
characters (7-bit will do) except , and /

I don't think there is any notation that lets me specify such a
character class easily, so I am stuck with making ranges that exclude
the characters I don't want.
This would be a real pain if I wanted to move beyond 7-bit characters.
What are some smarter ways of doing this?
I am interested in a regular expression because I am working with the
RecDescent module, which uses regular expressions to find tokens. I
have some text fields which are not allowed to contain . and /

--
Tim Richardson
(search string: qweeblebeast)

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Wed, 18 Jun 1902 08:00:00 GMT  
 Regexp char class: mixing ranges and negation?

Quote:

>I'm lazy. I want a regular expression that will match all visible
>characters (7-bit will do) except , and /

>I don't think there is any notation that lets me specify such a
>character class easily, so I am stuck with making ranges that exclude
>the characters I don't want.

How about lookahead:

        (?=[\000-\177])[^\/,]

(untested)

I don't think it's nearly as fast as a simple chartacter class, though.

--
        Bart.



Wed, 18 Jun 1902 08:00:00 GMT  
 Regexp char class: mixing ranges and negation?

Quote:

>I'm lazy. I want a regular expression that will match all visible
>characters (7-bit will do) except , and /

  [^,/\0-\037\177-\377]

If you want to allow printable 8-bit ISO Latin characters, replace
\377 with \237.

--
Ilmari Karonen - http://www.sci.fi/~iltzu/
Please ignore Godzilla and its pseudonyms - do not feed the troll.



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. RegExp Char Class

2. Why no regex char class for punc chars???

3. Regexp: shell glob negation

4. Regexp equivalent to shell glob negation

5. REGEXP: Mixed-case matching?

6. implicit vs explicit variable usage in loop w/ range regexp

7. matching . *and* \n in a char class

8. s2p fails with quotes in char classes

9. backslash escaping not metacharacters in a char class

10. different handling of = on unix and windows (in char class)

11. different handling of = on unix and windows (in char class)

12. Defining regular expression char class

 

 
Powered by phpBB® Forum Software