Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

To remove a certain pattern that is followed by numbers

by Anonymous Monk
on Jun 29, 2009 at 08:58 UTC ( [id://775589]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

All, I have the following string. I need to find the position and also remove the word "AS" that precedes a number. In this case there are two "AS". One is available in the word "ASPIRE" and another one in "AS1954". I need help in finding the position and also remove the word "AS" that precedes a number i.e. "AS1954".

ACER ASPIRE SERIES AS1954-526352BN

Thanks
  • Comment on To remove a certain pattern that is followed by numbers

Replies are listed 'Best First'.
Re: To remove a certain pattern that is followed by numbers
by ELISHEVA (Prior) on Jun 29, 2009 at 09:04 UTC

    Normally this is done with a regular expression or possibly index (for the position of the substring 'AS'). See perlretut for further explanation of regular expressions. Once you have read the documentation for index and regular expressions, please make a first attempt on you own. If you still can't get it to work as you want, come back, show us what you have done, and we'll be happy to help you sort it out.

    Best, beth

      Thanks. Will try again and get back, if not possible.
Re: To remove a certain pattern that is followed by numbers
by Corion (Patriarch) on Jun 29, 2009 at 09:04 UTC

    So what code have you written and where do you encounter problems?

    This is not a program writing service. This site is about learning and programming Perl. We will help you with your existing code, or with general advice on how to best proceed, but we will neither do your homework nor your pay-work for you.

    You will likely want to read perlretut and/or index, depending on how you want to approach this problem.

Re: To remove a certain pattern that is followed by numbers
by targetsmart (Curate) on Jun 29, 2009 at 09:04 UTC
    Nice question, try finding ways to solve your quest from perlretut, did you tried atleast a one-liner?


    Vivek
    -- 'I' am not the body, 'I' am the 'soul', which has no beginning or no end, no attachment or no aversion, nothing to attain or lose.
Re: To remove a certain pattern that is followed by numbers
by jwkrahn (Abbot) on Jun 29, 2009 at 09:10 UTC
    $ perl -le' $_ = "ACER ASPIRE SERIES AS1954-526352BN"; print; s/AS(?=\d)//g; print; ' ACER ASPIRE SERIES AS1954-526352BN ACER ASPIRE SERIES 1954-526352BN
      Thanks a lot, Sir.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://775589]
Approved by ELISHEVA
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-04-24 03:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found