stupid regexp question

S

Steve Linberg

For whatever reason, I'm suffering a massive brain cramp today and I
just can't figure this simple thing out, and I'm already embarrassed
about it so please don't rub it in too hard. :) Digging through man
pages, google, and the Camel isn't putting an answer in front of me that
my addled head can grok. If anybody can supply a hefty dope-slap for
what I'm sure is a simple task, I'd be most appreciative.

I just need a regexp that says "match any complete string not equal to
'mysql' or 'test'."

I can't use "!~ /^(mysql|test)$/" because this is an argument to feed to
a script that uses a positive search and puts the regexp in
$opt{regexp}, for use as in "=~ /$opt{regexp}/". Yes, I can hack the
script, but I'd rather not if I can avoid it.

The specific task is for mysqlhotcopy, where you can provide a regexp
for databases to dump. I want to tell it to dump everything EXCEPT
"mysql" and "test", so I need a single positive regexp that matches
everything except those two strings. For the life of me, I just can't
get my brain to spit it out.

(holding still for dope-slap)

TIA.
 
S

Steven Kuo

On Mon, 19 Apr 2004, Steve Linberg wrote:

(snipped) ...
I just need a regexp that says "match any complete string not equal to
'mysql' or 'test'."

I can't use "!~ /^(mysql|test)$/" because this is an argument to feed to
a script that uses a positive search and puts the regexp in
$opt{regexp}, for use as in "=~ /$opt{regexp}/". Yes, I can hack the
script, but I'd rather not if I can avoid it.

The specific task is for mysqlhotcopy, where you can provide a regexp
for databases to dump. I want to tell it to dump everything EXCEPT
"mysql" and "test", so I need a single positive regexp that matches
everything except those two strings. For the life of me, I just can't
get my brain to spit it out.




Negative look-ahead? This will allow you to use the '=~' operator.
For example,


print if ( $_ =~ /^(?!mysql$|test$)/ );

# or less verbose:

print if /^(?!mysql$|test$)/;
 
S

Steve Linberg

Steven Kuo said:
On Mon, 19 Apr 2004, Steve Linberg wrote:

(snipped) ...





Negative look-ahead? This will allow you to use the '=~' operator.
For example,


print if ( $_ =~ /^(?!mysql$|test$)/ );

# or less verbose:

print if /^(?!mysql$|test$)/;

Perfect. Thank you very much. :)

I'd been messing with negative lookahead, but I hadn't hit on that
syntax - if I recall, I had this:

/^?!(mysql|test)$/

....which I know is wrong, but I'll have to study it a bit more to find
out why. But your solution works great. Thanks for the slap/pointer! :)

- Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Stupid perl regexp question 6
Stupid question 29
regexp 9
Regexp question 5
Regexp: non greedy? 2
Regexp question... 2
Stupid Question 2
Multiple substitutions with Regexp::Common? 1

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top