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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:41:50+00:00 2026-05-20T07:41:50+00:00

I’m a rookie trying to search a text file for some serial numbers. I’m

  • 0

I’m a rookie trying to search a text file for some serial numbers. I’m using PHP 5 and I am reading out of a CSV file. I have created the following regular expression:

/^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$/

I’m looking through a rather large text file for serial numbers that resemble the one listed below:

37DB4B71-DAFA-4311-9AC6-0005646CB9BC

It always finds the first serial number, but it does not find any of the others. There are at least 15 others, any suggestions on what I’m doing wrong? It was my impression that \w will find either a number or digit in-case sensitive. I figured it worked as it found the first instance.

Here is the code I am using to parse the CSV file, I’m just bringing the whole file in and trying to split it into an array by serial number. Below is the code I am using to see if I can at least get the serial numbers split before I do anything else. Right now it shows me an array with 1 item inside. That one item is the serial number followed by a bunch of text and the serial numbers I need.

One more thing, the reason I’m using preg_split is because the serial number is followed by a comma and then some details about the serial number. I was trying to use Preg_split to break the file so the text would follow the serial number.

$searchPattern = '/^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$/';
//Get the contents of the File
$contents = file_get_contents('C:/files/andrew1.csv'); 
if ($contents === false){
    echo 'Sorry, there was a problem reading the file.';
} else{
    $NoHTMLContents = strip_tags($contents);
    $splitContents = preg_split($searchPattern, $NoHTMLContents);
    echo '<pre>';
    print_r($splitContents);
    echo '</pre>';
}
  • 1 1 Answer
  • 1 View
  • 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-20T07:41:50+00:00Added an answer on May 20, 2026 at 7:41 am

    It would help if you posted your code, but I’m guessing that you need to use preg_match_all instead of preg_match as the latter only returns the first match.

    You should also remember to use the PCRE_MULTILINE pattern modifier (m):

    preg_match_all('/^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$/m', $s, $matches);
    

    See it working online: ideone


    For a preg_split based approach, try using a lookahead:

    $matches = preg_split("/\n(?=\w{8}-\w{4}-\w{4}-\w{4}-\w{12})/m", $s);
    

    See it working online: ideone

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a reasonable size flat file database of text documents mostly saved in
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am trying to render a haml file in a javascript response like so:
This could be a duplicate question, but I have no idea what search terms

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.