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

  • SEARCH
  • Home
  • 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 930319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:18:52+00:00 2026-05-15T20:18:52+00:00

I am parsing a text file and I get multiple lines in the form

  • 0

I am parsing a text file and I get multiple lines in the form shown below.

Then I try to split each line to three segments: Part1: sf; part2: name; part3:direction.

But now I am encountering difficulty in how to write my regular expression. I have thought about splitting on whitespace and using an array to concatenate new strings:

S15,F49  Large Recipe Download Request (LRDR)   S,H->E,reply

my ($sf, $name, $direction) =~ / I don't know how to implement here/

How can I get $sf = S15,F49 // other lines like S1,F11; S6,F1; etc

$name = Large Recipe Download Request (LRDR) // different name for different $sf.

$direction = S,H->E,reply; // some time it is M,H<-E,reply or S,H<->E or S,H->E,[reply], etc. There is no white space between each of sub items for part3: $direction

  • 1 1 Answer
  • 2 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-05-15T20:18:53+00:00Added an answer on May 15, 2026 at 8:18 pm

    If there is no whitespace within the $sf and the $direction items, then you could apply the following code to each line:

    if ($subject =~ m/^(\S+)\s+(.*?)\s+(\S+)$/) {
        $sf = $1;
        $name = $2;
        $direction = $3;
    } else {
        // no match found
    }
    

    Explanation:

    ^: Anchor the regex at the start of the string.

    (\S+): Match one or more non-space characters. Capture the match in $1.

    \s+: Match one or more space characters (= separator(s) to the next item).

    (.*?): Match any number of characters, as few as possible to still allow the overall match to succeed, and capture that in $2.*

    \s+(\S+): Similar to the above – match space separator(s) and non-space characters –> $3.

    $: Anchor the search at the end of the string.


    *The reason for the lazy quantifier *? is that otherwise, this part of the regex would also capture all the following space separators except the last one.

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

Sidebar

Related Questions

I am parsing an input text file. If I grab the input one line
Parsing a text file in vb.net and need to locate the latitude and longitude
I have two arrays built while parsing a text file. The first contains the
I'm parsing text from a file and storing it in a string. The problem
I am parsing text that has a heading and then data that applies to
I'm tasked with reading a large text file (around 150 MB), parsing it and
I can't get a doctest to work with a result which contains multiple lines
My question is quite simple. I need to get all text lines from Windows
I'm parsing an XML file an get a string as NSMutableString . Now I
Apart from just inserting and parsing text into a blank Word field, is there

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.