Re: to parse a string
- From: "John W. Krahn" <someone@xxxxxxxxxxx>
- Date: Fri, 28 Oct 2005 11:15:04 GMT
Tassilo v. Parseval wrote:
> Also sprach Tad McClellan:
>
>>cc <mmzzcc.c@xxxxxxxxx> wrote:
>>
>>>Given a string, e.g. "01010123", any sample code to scan it and then
>>>find the "2" and "3" are not qualified in the string which requires
>>>only "0" and "1"?
>>
>>The usual idiom for validating data is:
>>
>> anchor the beginning.
>>
>> anchor the ending.
>
> Why the anchoring?
>
>> write a regex in between that accounts for everything
>> that you want to allow.
>>
>>
>>print "'$str' is bad data\n" unless $str =~ /^[01]+$/;
>
> Or use tr:
>
> print "'$str' is bad data\n" if $str =~ tr/^01//c;
^
Are you sure that caret is supposed to be there?
John
--
use Perl;
program
fulfillment
.
- Follow-Ups:
- Re: to parse a string
- From: Anno Siegel
- Re: to parse a string
- References:
- Re: to parse a string
- From: Tad McClellan
- Re: to parse a string
- From: Tassilo v. Parseval
- Re: to parse a string
- Prev by Date: Re: search & relplace question
- Next by Date: Re: to parse a string
- Previous by thread: Re: to parse a string
- Next by thread: Re: to parse a string
- Index(es):
Relevant Pages
|