Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Regex: Matching Characters NOT in a Certain Range

Reply
Thread Tools

Regex: Matching Characters NOT in a Certain Range

 
 
Hal Vaughan
Guest
Posts: n/a
 
      10-04-2005
I can't find this in the FAQ, but I thought it was. If I have a range of
characters, like [a-zA-Z], how can I specify that I want to match any
character NOT in that range? (Yes, I know this is close to /W and /w, but
this is only an example).

I thought I remembered a characer I could use to invert a match like this so
if I were doing:

$line =~ s/[a-zA-Z]/x/g;

that if I used it, I could replace all characters NOT matching that range
instead of the ones that do.

Is there such a way to do this, or do I mis-remember?

Thanks!

Hal
 
Reply With Quote
 
 
 
 
Anno Siegel
Guest
Posts: n/a
 
      10-04-2005
Hal Vaughan <(E-Mail Removed)> wrote in comp.lang.perl.misc:
> I can't find this in the FAQ, but I thought it was. If I have a range of
> characters, like [a-zA-Z], how can I specify that I want to match any
> character NOT in that range? (Yes, I know this is close to /W and /w, but
> this is only an example).
>
> I thought I remembered a characer I could use to invert a match like this so
> if I were doing:
>
> $line =~ s/[a-zA-Z]/x/g;
>
> that if I used it, I could replace all characters NOT matching that range
> instead of the ones that do.


Have you looked at perlre? You're looking for "^".

Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
 
Reply With Quote
 
 
 
 
Hal Vaughan
Guest
Posts: n/a
 
      10-04-2005
Anno Siegel wrote:

> Hal Vaughan <(E-Mail Removed)> wrote in comp.lang.perl.misc:
>> I can't find this in the FAQ, but I thought it was. If I have a range of
>> characters, like [a-zA-Z], how can I specify that I want to match any
>> character NOT in that range? (Yes, I know this is close to /W and /w,
>> but this is only an example).
>>
>> I thought I remembered a characer I could use to invert a match like this
>> so if I were doing:
>>
>> $line =~ s/[a-zA-Z]/x/g;
>>
>> that if I used it, I could replace all characters NOT matching that range
>> instead of the ones that do.

>
> Have you looked at perlre? You're looking for "^".


That's it!

I can never remember all the terms to search for. I tried regular
expression, regex and re. Forgot perlre.

I thought ^ was to match the beginning of a line, so my brain just wouldn't
accept it -- and I forgot to put it INSIDE the brackets!

Thanks!

Hal
 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      10-04-2005
Hal Vaughan <(E-Mail Removed)> wrote in
news:(E-Mail Removed):

> Anno Siegel wrote:


....

>> Have you looked at perlre?


....

> I can never remember all the terms to search for.


perldoc perltoc

Sinan

--
A. Sinan Unur <(E-Mail Removed)>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/cl...uidelines.html
 
Reply With Quote
 
Alan J. Flavell
Guest
Posts: n/a
 
      10-04-2005
On Tue, 4 Oct 2005, Hal Vaughan wrote:

> Anno Siegel wrote:
>
> > Have you looked at perlre? You're looking for "^".

>
> That's it!
>
> I can never remember all the terms to search for. I tried regular
> expression, regex and re. Forgot perlre.
>
> I thought ^ was to match the beginning of a line, so my brain just
> wouldn't accept it -- and I forgot to put it INSIDE the brackets!


You have to keep a clear distinction between the mini syntax which
applies for character classes (inside [ ] ), and the more usual syntax
in regular expressions in general.
 
Reply With Quote
 
Hal Vaughan
Guest
Posts: n/a
 
      10-04-2005
A. Sinan Unur wrote:

> Hal Vaughan <(E-Mail Removed)> wrote in
> news:(E-Mail Removed):
>
>> Anno Siegel wrote:

>
> ...
>
>>> Have you looked at perlre?

>
> ...
>
>> I can never remember all the terms to search for.

>
> perldoc perltoc


Thanks. I never knew that! (Seriously -- I was used to searching for
terms, but never new there was a toc!)

Hal
 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      10-04-2005
Hal Vaughan <(E-Mail Removed)> wrote:
> A. Sinan Unur wrote:
>
>> Hal Vaughan <(E-Mail Removed)> wrote in
>> news:(E-Mail Removed):
>>
>>> Anno Siegel wrote:

>>
>> ...
>>
>>>> Have you looked at perlre?

>>
>> ...
>>
>>> I can never remember all the terms to search for.

>>
>> perldoc perltoc

>
> Thanks. I never knew that! (Seriously -- I was used to searching for
> terms, but never new there was a toc!)



Then you must have not even tried the somewhat obvious:

perldoc perl

which also lists the std docs, including the ToC.


--
Tad McClellan SGML consulting
http://www.velocityreviews.com/forums/(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Windows Vista cannot obtain an IP address from certain routers or from certain non-Microsoft DHCP Brian W Wireless Networking 7 01-31-2010 03:46 AM
DNS to certain IP range on internal network not resolving? atsadmin Cisco 0 07-25-2006 04:33 PM
Expanding certain path to certain node in a JTree arun.hallan@gmail.com Java 0 01-08-2005 08:26 PM
Pattern matching : not matching problem Marc Bissonnette Perl Misc 9 01-13-2004 05:52 PM
Net send - allow only certain IP range with ZoneAlarm (normal - not pro) Computer Support 0 11-03-2003 07:46 PM



Advertisments