www.webdeveloper.com
Results 1 to 3 of 3

Thread: RegEx help

  1. #1
    Join Date
    Mar 2012
    Posts
    41

    RegEx help

    I have a text file that has some text and in it contains some blocks that looks like
    ...
    ...
    Tuesday, October 08, 2013
    ...
    ...

    Wednesday, October 09, 2013
    ...
    ...
    Now what I want to do is find those block for further processing. Now Im no regex expert
    but this is what I got so far.
    PHP Code:
    $test  "^(Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday),.*$(\n|\r)";
    $matches = array();
    preg_match_all($test$text$matchesPREG_SET_ORDER); 
    But it obviously does not work. Id appreciate all the pointer/help I could get..

  2. #2
    Join Date
    Sep 2013
    Posts
    221
    well..., i think for variable matches try with the below code:

    $def = $matches[0];
    echo $def;

    Hope this helps.

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,637
    I'd probably let trim() take care of the line endings.
    PHP Code:
    $lines file('path/to/file.txt'FILE_SKIP_EMPTY_LINES);
    $regex '^(?:Mon|Tues|Wednes|Thurs|Fri|Satur|Sun)day,.*$';
    foreach(
    $lines as $line) {
      if(
    preg_match($regextrim($line), $matches)) {
        echo 
    "<p>{$matches[0]}</p>\n";
      }

    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles