Re: Stripping numbers from a string




Matt Garrish wrote:
> "it_says_BALLS_on_your forehead" <simon.chao@xxxxxxx> wrote in message
> news:1138660045.508919.71590@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> >
> > Ninja67 wrote:
> >> This should be an easy one for you seasoned perl developers.
> >>
> >> I've got a string that may or may not begin with one or more numbers.
> >> For example, it might be "Smith, John" or it might be "83Smith, John".
> >>
> >> I only want the text portion of the string. How do I make sure that
> >> regardless of which of the above is passed to me, I only get "Smith,
> >> John"?
> >
> >
> > my $string = '83Smith, John';
> > $string =~ s/\d//g;
> >
>
> Or more safely:
>
> $string =~ s/^\d+//;
>
> Who knows when you'll run into "83Smith 4th, John"...

excellent point. when i read that the OP only wanted the text portion
of the string, i (possibly erroneously) designed a simple regex to
delete all digits from the string, regardless of position. i should
have looked more closely at the OP's first paragraph.

.



Relevant Pages

  • Split Single Address Field into Component Parts
    ... would make a copy of the database before making any ... would subtract that part of the string from the working ... I ran an update query to extract the portion of the ...
    (microsoft.public.access.queries)
  • Split Single Address Field into Component Parts
    ... >address field using an update query. ... >string functions. ... I ran an update query to extract the portion of the ...
    (microsoft.public.access.queries)
  • Re: atoi return
    ... the "initial portion of the string" can be ... sequence of white-space characters (as specified by the isspace ... terminating null character of the input string. ...
    (comp.lang.c)
  • Re: Find Replace
    ... pin" to "end vss". ... And then delete some lines within that portion. ... string buffer the [split ... ... puts $line should be moved into the if statement, ...
    (comp.lang.tcl)
  • Re: Why strNlen is not in Std ?
    ... "Compare a portion of one string to a portion of another." ... Expressed in this posting are my opinions. ... to opinions held by my employer, Sun Microsystems. ...
    (comp.std.c)