Re: Simple RegEx to pull out content between 2 markers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jon Bennett wrote:
Hi,

I need to grab the what's between 2 markers in a Textile / html
string, but my regex skills aren't all that hot. The text I have is:

<OPEN_MAIN_COLUMN>

h3. Article Content

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
minim veniam, quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
culpa qui officia deserunt mollit anim id est laborum.

p(image). !/app/image/1/large! Caption

p(image). !/app/image/24/large! drunken jonty

<CLOSE_MAIN_COLUMN>

<OPEN_LEFT_COLUMN>

h3. Article Content

!/app/image/7/thumb! Lorem ipsum dolor sit amet, consectetur
adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore
magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation
ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute
irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident,
sunt in culpa qui officia deserunt mollit anim id est laborum.

<CLOSE_LEFT_COLUMN>

<CLOSE_RIGHT_COLUMN>

h3. Article Content

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua.

* Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
nisi ut aliquip ex ea commodo consequat.
* Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur.
* Excepteur sint occaecat cupidatat non proident, sunt in culpa qui
officia deserunt mollit anim id est laborum.

<CLOSE_RIGHT_COLUMN>

I'd like to grab the contents of left, right and main individually so
I can place them in separate form fields.

Any help greatly appreciated. I'm certain this is a cinch for people
who use regex often.

It's really not that hard if you use three separate expressions:

$left = preg_match('/<OPEN_LEFT_COLUMN>(.*)<CLOSE_LEFT_COLUMN>/is', $text, $matches);

$right = preg_match('/<OPEN_RIGHT_COLUMN>(.*)<CLOSE_RIGHT_COLUMN>/is', $text, $matches);

$main = preg_match('/<OPEN_MAIN_COLUMN>(.*)<CLOSE_MAIN_COLUMN>/is', $text, $matches);

And then, IIRC, the content you're after will be in $matches[1].

--
Richard Heyes
Employ me:
http://www.phpguru.org/cv

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux