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 6137109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:41:07+00:00 2026-05-23T17:41:07+00:00

I have a bunch of strings in a text file that have values in

  • 0

I have a bunch of strings in a text file that have values in them I want to capture into groups. Each line/row in the text file is a unique record, but the values usually stick to a prescribed format in each line:

ValueA ValueD ValueS ValueR ValueW ValueT
ValueX ValueW ValueB ValueM ValueQ ValueA

Etc. If I want to capture ValueA into capture group 1 and ValueW into capture group 2, can I do so using a single regex that handles things properly irrespective of the position in each line of text of the values in question?

The goal is to then use the capture groups to write back out to a file the two captured values so that I can order them, i.e., “ValueW ValueA”.

  • 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-05-23T17:41:08+00:00Added an answer on May 23, 2026 at 5:41 pm

    You could use something like:

    ^(?=.*?(ValueA))(?=.*?(ValueW)).*
    

    Perl example:

    $_ = <<'_STR_';
    ValueA ValueD ValueS ValueR ValueW ValueT
    ValueX ValueW ValueB ValueM ValueQ ValueA
    _STR_
    
    s/^(?=.*?(ValueA))(?=.*?(ValueW)).*/$1 $2/gm;
    
    print;
    

    Output:

    ValueA ValueW
    ValueA ValueW
    

    Also at http://ideone.com/IhGfS

    Note: If you are just matching you won’t need that last .*, and depending on how well matching the ValueX patterns are you could remove all the ?.

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

Sidebar

Related Questions

What I have is a giant text file that contains a bunch of strings
I have a bunch of strings that are dependent on static dictionaries and each
I have a bunch of string with special escape codes that I want to
I have a bunch of text files that were encoded in UTF-8 . The
Hello I have a bunch of text on my file which i display. I
I have a flat file that I'm trying to scrub for import into a
I have a code as such that reads in an xml file into a
I have a bunch of strings that may or may not have a substring
I have a process in R that creates a bunch of objects, serializes them,
I have an application that crunches a bunch of text files. Currently, I have

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.