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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:36:14+00:00 2026-05-24T23:36:14+00:00

I realize that this is probably not the smartest thing to do with regular

  • 0

I realize that this is probably not the smartest thing to do with regular expressions but I was wondering if it is possible in theory.

Given a text-file example:

MYL3    P08590
MYL3    B2R534
MYL3    Q9NRS8
TM38A   Q9H6F2
TM38A   A8K9P9
TRFE    P02787
TRFE    O43890
TRFE    Q1HBA5
TRFE    Q9NQB8
TRFE    Q9UHV0
ETFA    P13804
KCRM    P06732
KCRM    Q96QL9

… would it be possible to match the lines that start with the same pattern as the previous line, just by use of regular expressions? Matching and replacing the lines (that match the criteria) with nothing would be something like:

MYL3    P08590
TM38A   Q9H6F2
TRFE    P02787
ETFA    P13804
KCRM    P06732

My guess is that even though it is possible to use multiple line matching to check the previous line, it wouldn’t be possible to accomplish just by regular expressions, as there is no defined pattern to match but instead just the first (couple of) word(s) in consecutive lines. It would require to define the beginning of a line as a “variable” and to compare the beginning of the next line to that, which as far as I know not possible with regex alone.

A colleague, on the other hand, claimed that it might be possible depending on the implementation of regex. I thought I would ask to the experts here.. 🙂

  • 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-24T23:36:14+00:00Added an answer on May 24, 2026 at 11:36 pm

    You can use this regex:

    (?s)(\w+)\s+\w+\r\n(\1\s+\w+(?:\r\n)?)+
    
    1. (?s) – single line option enabled
    2. (\w+) – alphanumeric (group 1), one or more repetitions
    3. \s+ – whitespace, one or more repetitions
    4. \w+ – alphanumeric, one or more repetitions
    5. \r\n
    6. (\1\s+\w+(?:\r\n)?) – group 2, one or more repetitions: back reference to group 1, whitespace, one or more repetitions, alphanumeric, one or more repetitions, \r\n zero ore one

    It will match:

    enter image description here

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

Sidebar

Related Questions

I half realize that this question is probably asked already, but I'm not familiar
I know that this sounds trivial, but I did not realize that the sort()
I realize that this is a question that will probably not have a single
I realize that this is probably a very basic question, but I have spent
I realize that this would be COMPLETELY bad practice in normal situations, but this
I realize that this question is impossible to answer absolutely, but I'm only after
I realize that this question has been asked 100times but none that I have
Ok so I realize that this is a pretty vague question, but bear with
I realize that there was a similar question asked here , but this is
I realize I am probably doing this completely wrong, but here is my issue...

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.