Dear Perl communinty,

I don't exactly want to ask this now, since  I just spent much of the
evening trying to handle this case, but I wonder if there's an easy way to
keep the following regular expression from matching if the string in the
regex is null:

$_ = ":B000:L520:M260:M:88:8:M602:";
$string_to_match="whatever";
$count = () = /\b($string_to_match)\b/g;

If $string_to_match is null, whatever's in $_ matches it -- and for some
reason i don't understand it matches twice for every colon-delimited piece
of $_, though that hardly matters.

Is there an easy way to keep the null string from matching anything?  It
would have saved me an evening if I'd known about it.

Thanks,

Scott

Scott E. Robinson
SWAT Team
UTC Onsite User Support
RR-690 -- 281-654-5169
EMB-2813N -- 713-656-3629


                                                                                       
                                     
                      "Rob Dixon"                                                      
                                     
                      <[EMAIL PROTECTED]       To:       [EMAIL PROTECTED]             
                                    
                      .co.uk>                  cc:                                     
                                     
                                               Subject:  Re: Searching for the right 
regular expressions                    
                                                                                       
                                     
                      03/24/03 10:08 AM                                                
                                     
                                                                                       
                                     
                                                                                       
                                     



Hi. Rading your post again, it looks like I kinda screwed up.
Lets try again!

Rob Dixon wrote:
> Hi Scott
>
> Scott E Robinson wrote:
> > Dear Perl experts,
> >
> > I'm trying to find the right regular expressions to do some simple
> > (?) string processing.  Can anyone tell me how to do these?
> >
> > 1.  Given a string consisting of substrings delimited by colons,
> > such as :B520:L201:M:M260:8:G607:,
>
>     my $string = ':B520:L201:M:M260:8:G607:';
>
> > how can I
> >       a. remove the single-character and all-numeric substrings (M
> > and 8 in this example), leaving the rest alone?
>
> This is an array of all the wanted substrings:
>
>     my @wanted = $string =~ /[a-z]\w+/ig;
>     print "@wanted\n";
>
> output
>
>     B520 L201 M260 G607

I think that's right, although it assumes that the values that aren't
all-numeric start with an alpha.

> >       b. remove all but the single-character and all-numeric
> > substrings and leave the rest alone?
>
> This is an array of all the wanted substrings:
>
>     my @wanted = $string =~ /\b\w\b/ig;
>     print "@wanted\n";
>
> output
>
>     M 8

Right result, but fails to find '88'. Try:

    my @wanted = $string =~ /\b\w\d*\b/ig;

> >       c. remove all but single- or double-character substrings and
> > all-numeric substrings and leave the rest alone?
>
> This is an array of all the wanted substrings:
>
>     my @wanted = $string =~ /\b[a-z]\w?\b/ig;
>     print "@wanted\n";
>
> output
>
>     M

This is right, I think.

> (Note that this won't find '8M', but your data doesn't look like
> that will come up.)
>


That's more like it!

Rob




--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]






-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to