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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:08:28+00:00 2026-06-16T07:08:28+00:00

I have a normal text files with each line having data in the following

  • 0

I have a normal text files with each line having data in the following format.

Mason, James, 13th Avenue, Alexandria, 5812347

Now what I wanted to do was to search for “Mason” in the file and when found, I’d have an array containing all the lines found. The question below does this perfectly with one main problem:

PHP to search within txt file and echo the whole line

PROBLEM: This searches the whole line if every line for a match, I just want to compare my string against the first word in the line or in other words, till the first comma is found.

I cannot seem to be able to “add” the needed modifications to the regular expression to the code provided in the question referenced above. Help would be very appreciated.

Thanks!

  • 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-16T07:08:29+00:00Added an answer on June 16, 2026 at 7:08 am
    preg_match_all(
        '/^    # Match the start of the line
        [^,]*  # Match any number of characters except commas
        Mason  # Match "Mason"
        .*     # Match the rest of the line/mx', 
        $subject, $result, PREG_PATTERN_ORDER);
    $result = $result[0];
    

    gets you all lines where Mason is found before the first comma.

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

Sidebar

Related Questions

I have ~300 text files that contain data on trackers, torrents and peers. Each
I have a huge text file with 25k lines.Inside that text file each line
I have a body of text that I have to scan and each line
I have some text/images that I only want to display in the normal state
I have a normal textbox in my application. I can paste data to it
Imagine you have a normal table view where each row is an item on
I have some text files which I am trying to transform with a Perl
I have an MVC3 web app via which users upload text files to the
Is there any tricky ways to do this: in my text files I have
I have two processes which exange messages each other. Process A is a normal

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.