#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2008
    Posts
    152
    Rep Power
    0

    Isolating results based on regular expressions


    I'm currently retruning random data from DOM Parser. The only thing that I want to keep out of all the data is the dates. For example, everything below may varry except the FORMAT OF THE DATES:

    aja ajlshfs d sd sdjfh sd fsd 2008/02/06 aklsd as dklas a sdkajs aslkd as da 2008/06/08 aslijas as asldhasjda sd asj as dasjdha sd 2008/11/12:

    Is there a function I can use to say get rid of everyhting and leave me with anything matching the regular expression below. The key here is that the information surrounding the dates is not consistent. The FORMAT OF THE DATES is the only thing consistent. I want to isolate based on the pattern below:

    PHP Code:
    $pattern '|^\d{4}/\d{1,2}/\d{1,2}$|'
    As a result, I'm left with:

    Code:
    2008/02/06
    2008/06/08
    2008/11/12
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2007
    Posts
    765
    Rep Power
    929
    Telling us the language you're used would help.

    Judging from your code though, I'm going to guess PHP. If you look at preg_match_all() . The third argument is an 2D-array in which the matches will be stored. Using the flag PREG_PATTERN_ORDER will store an array of the full patern matches in $array[0]. You can use join if you need them in a single string.
    sub{*{$::{$_}}{CODE}==$_[0]&& print for(%:: )}->(\&Meh);
  4. #3
  5. No Profile Picture
    I haz teh codez!
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2003
    Posts
    2,555
    Rep Power
    2338
    It's PHP, he cross-posted it there.

IMN logo majestic logo threadwatch logo seochat tools logo