Re: to parse a string



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.
.



Relevant Pages

  • Re: folding anchor???
    ... Attach the chain on the warp to the loop at the centre of the 'bottom' of the anchor. ... Then run the chain alond the shaft to the 'top' and attach to the ring with a mediun sized cable tie / 60 lb nylon. ...
    (uk.rec.fishing.sea)
  • Re: Columns line between problem
    ... Here is the thing I don't think a gap ... looks good on the top and/or bottom. ... even if I lock the anchor it will still be deleted. ... the header and that way I thought it would only delete the anchor if I ...
    (microsoft.public.word.pagelayout)
  • Re: Anchoring
    ... Lower the anchor gently to the bottom (you can feel when it ... > wind or tide, or motor gently backwards if there is none. ... Let out chain as you go - ...
    (uk.rec.sailing)
  • Re: Anchoring
    ... Have your chain marked every 5 metres or so, with different marks, so you ... Lower the anchor gently to the bottom (you can feel when it hits ... wind or tide, or motor gently backwards if there is none. ...
    (uk.rec.sailing)
  • Re: form resizing
    ... boxes on my form and set the top textbox anchor to left, ... the bottom text box anchor to bottom, left, right - they get this big gap in ... How do I get it so the two text boxes ... >> the textbox on top stretches underneath the textbox below it... ...
    (microsoft.public.dotnet.languages.csharp)