[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: OT: RE madness



On Mon, Jan 06, 2003 at 11:40:08PM -0200, andrej hocevar wrote:
| Hello.
| I've been playing around with these two REs in Perl with no
| success. Can anyone tell me what's wrong?

Disclaimer:
    I assume !~ means "does not match".
    (I don't do perl)
    (However, I know that =~ means "matches")

| This works:
| !~ /^(?:red|blue)$/
| 
| and will match everything except any of the two fixed strings
| "red" or "blue" or any combination thereof.

The regex will match only the string "red" or "blue", no combinations.
The expression will be true iff the regex doesn't match.

| "black" matches, as does "blu", because it's neither red nor blue.

Close but not quite.  The _regex_ doesn't match, but the expression is
true.

| Then I wanted to convert the above expression to a "positive"
| match, like this:
| =~ /^[^(?:red|blue)]$/
       ^             ^
What do square brackets mean?  (hint: _character_ class)

A successful match with that expression will consist of :
    .   start of input/line/string)
    .   any single character as long as it is not one of bdelru()?:|.
    .   end of input/line/string

| which fails.  Why is this?

You didn't say what you meant to say :-).  Computers only do what you
say, not what you mean.

| Is there no way of saying "neither/nor", just "either/or"?

That is correct (AFAIK).

-D

-- 
"Wipe Info uses hexadecimal values to wipe files. This provides more
security than wiping with decimal values." -- Norton SystemWorks 2002 Manual
 
http://dman.ddts.net/~dman/

Attachment: pgphVSIAoAa4k.pgp
Description: PGP signature


Reply to: