Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8473293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:18:37+00:00 2026-06-10T17:18:37+00:00

I would like to write a script which can return me the result whenever

  • 0

I would like to write a script which can return me the result whenever the regex meet.I have some difficulties in writing the regex i guess.

Content of My input file is as below:

 Number a123;
     Number b456789 vit;
 alphabet fty;

I wish that it will return me the result of a123 and b456789, which is the string after “Number ” and before (“\s” or “;”).
I have tried with below cmd line:

 my @result=grep /Number/,@input_file;
 print "@results\n";

The result i obtained is shown below:

  Number a123;
     Number b456789 vit;

Wheareas the expected result should be like below:

a123
b456789

Can anyone help on this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T17:18:39+00:00Added an answer on June 10, 2026 at 5:18 pm

    Perls grep function selects/filters all elements from a list that match a certain condition. In your case, you selected all elements that match the regex /Number/ from the @input_file array.

    To select the non-whitespace string after Number use this Regex:

    my $regex = qr{
      Number     # Match the literal string 'Number'
      \s+        # match any number of whitespace characters
      ([^\s;]+)  # Capture the following non-spaces-or-semicolons into $1
                 # using a negated character class
    }x;          # use /x modifier to allow whitespaces in pattern
                 # for better formatting
    

    My suggestion would be to loop directly over the input file handle:

    while(defined(my $line = <$input>)) {
      $line =~ /$regex/;
      print "Found: $1" if length $1; # skip if nothing was found
    }
    

    If you have to use an array, a foreach-loop would be preferable:

    foreach my $line (@input_lines) {
      $line =~ /$regex/;
      print "Found: $1" if length $1; # skip if nothing was found
    }
    

    If you don’t want to print your matches directly but to store them in an array, push the values into the array inside your loop (both work) or use the map function. The map function replaces each input element by the value of the specified operation:

    my @result = map {/$regex/; length $1 ? $1 : ()} @input_file;
    

    or

    my @result = map {/$regex/; length $1 ? $1 : ()} <$input>;
    

    Inside the map block, we match the regex against the current array element. If we have a match, we return $1, else we return an empty list. This gets flattened into invisibility so we don’t create an entry in @result. This is different form returning undef, what would create an undef element in your array.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to write an SQL script or query which can decide that
I would like to write a script which will edit multiple XML files, I
Is Delphi have any ability to write script of IDE actions? I would like
I would like to write a script which copies my current database sitedb1 to
I would like to write a League Fixture generator in python, but I can't.
I would like to write the SQL (MS SQL 2005/08) script to insert random
Have been trying to write an awk script which processes a log file, but
i have some text file which contain proxy ip . which look like following
I have some old code with document.write in it. <script type=text/javascript language=JavaScript1.2> document.write('<form name=InvGenPayDonation
I would like to write an abstract base class class func_double_double_t : public unary_function<double,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.