August 25th, 2008, 12:39 PM
-
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
August 25th, 2008, 04:16 PM
-
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);
August 25th, 2008, 09:10 PM
-