regex issue

General discussions related to php

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 2
Joined: Tue Jun 10, 2014 5:27 pm

regex issue

Postby edwardsmarkf » Tue Jun 10, 2014 5:41 pm

hello all - first time posting to this forum.

i am trying to use preg_match_all, but i am running into trouble. in plain English, i want to parse out everything in the quotes. for some reason, i cant seem to use the closing angle-bracket. i tried just ">" and "\>" but no luck. the first example without the closing angle-bracket works fine, but the subsequent ones only grab the LAST span occurrence and ignores the first one.

(for the regex-challenged, the ?: tells regex to skip indexing the value in the parenthesis)

if somebody could please have a look at this code and see what i am doing wrong i would appreciate it!

Code: Select all

$string = '<span style="font-size:10px;"><span style="color:#aaaaaa;">test font</span></span>';

preg_match_all('/(?:<span style="([a-z-]+:[a-z0-9#]+;)")+/', $string, $matches);

preg_match_all('/(?:<span style="([a-z-]+:[a-z0-9#]+;)">)+/', $string, $matches);
//                   i added this right angle-bracket: >

preg_match_all('/(?:<span style="([a-z-]+:[a-z0-9#]+;)"\>)+/', $string, $matches);
//          i added this back-slash and angle-bracket: \>

thank you all very much.

PHP 5.3.3 (cli) (built: Dec 11 2013 03:29:57)

Return to “PHP General”

Who is online

Users browsing this forum: No registered users and 3 guests