Posted on 2005-05-04
Last Modified: 2010-03-05
i have string in followin format
app.txt_050405-10:22:25 is up and running now

how do i extract the  "app" from string
Question by:shahrahulb

    Expert Comment


    If you JUST want to remove it, a quick dirty way is to do this:

    $line =~ s/app//gsi;

    this will just remove it.
    LVL 1

    Author Comment

    app is variable and not constant value
    LVL 28

    Expert Comment

    When you say 'extract' do you mean you want to remove it or put it into another variable?

    #!perl -w

    $str = 'app.txt_050405-10:22:25';

    $str =~ s/^([^\.]+)//;
    $extracted = $1;
    print "extracted/removed '$extracted' from $str$/";

    extracted/removed 'app' from .txt_050405-10:22:25
    LVL 28

    Accepted Solution

    Actually, the . does not need to be escaped in the characture class so, it can be written as;

    LVL 16

    Expert Comment

    $str =~ s/^([^\.]+)//;
    $extracted = $1;
    print "extracted/removed '$extracted' from $str$/";

    if $str contains all '.' (or if it starts with a '.'), this may match a stale $1 from a previous successfull match. As I've heard, this is not a good idea. $n should be accessed only after checking whether the match was successful.

    $extracted = $1 if ($str =~ m/^([^.]+)/) ;


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
    There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now