Re: to parse a string
- From: anno4000@xxxxxxxxxxxxxxxxxxxxxxx (Anno Siegel)
- Date: 28 Oct 2005 11:21:25 GMT
John W. Krahn <krahnj@xxxxxxxxx> wrote in comp.lang.perl.misc:
> 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?
Yes, in Middle-High-Perl where double negation is the norm.
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.
.
- References:
- Re: to parse a string
- From: Tad McClellan
- Re: to parse a string
- From: Tassilo v. Parseval
- Re: to parse a string
- From: John W. Krahn
- Re: to parse a string
- Prev by Date: Re: to parse a string
- Next by Date: Re: search & relplace question
- Previous by thread: Re: to parse a string
- Next by thread: Re: Using regex to remove "redundant" tags
- Index(es):
Relevant Pages
|