[wp-trac] [WordPress Trac] #24225: Improve regular expressions when matching attributes

WordPress Trac noreply at wordpress.org
Fri Oct 17 10:23:48 UTC 2014


#24225: Improve regular expressions when matching attributes
-------------------------+------------------------
 Reporter:  kovshenin    |       Owner:  kovshenin
     Type:  enhancement  |      Status:  assigned
 Priority:  normal       |   Milestone:  4.1
Component:  Formatting   |     Version:  3.6
 Severity:  normal       |  Resolution:
 Keywords:  has-patch    |     Focuses:
-------------------------+------------------------

Comment (by kovshenin):

 Replying to [comment:17 miqrogroove]: It should match the correct
 attribute if you added something like `.*?\2` instead of `\s?` to the end
 of the regex. This works in Perl:

 {{{
 $html = 'value="hello class=\'world alignright" class="foo alignnone"';
 if ( $html =~
 /(class=(["\'])(?:[^\'"]|(?!\2).)*?)align(none|left|right|center).*?\2/ )
 {
         print "$1\n";
 }
 }}}

 But it doesn't work in PHP :) I don't really know why. But you're right,
 this is not worth the effort, and as I said, the patch was just for
 reference as a way to match attributes with negative lookahead, just in
 case we ever want to revisit [http://stackoverflow.com/a/1732454/24894
 parsing HTML with regex] again.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/24225#comment:18>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list