note 102285 added to regexp.reference.conditional

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
Repetition of a subpattern will repeat conditionals that are contained inside it, updating subpattern matches with iteration.

Consider the following code, which scans thru HTML, keeping track of angle brackets "<" ">".  If open bracket "<" matches, then closing bracket ">" must follow before repetition can possibly end.  That way regex will effectively match only outside of tags. 

<?php
$pattern='%(*ANY)(.*?(<)(?(2).*?>)(.*?))*?\'\'%s';
$replace='\1Fred';
$subject=
'<html><body class=\'\'>\'\' went to '\'\meyer and ran 
into <b>\'\'</b>.
</body></html>'
		echo preg_replace($pattern,$replace,$subject);
?>

Output will be:
'<html><body class=\'\'>Fred went to Fredmeyer and ran 
into <b>Fred</b>.
</body></html>'
----
Server IP: 69.147.83.197
Probable Submitter: 24.113.79.192
----
Manual Page -- http://www.php.net/manual/en/regexp.reference.conditional.php
Edit        -- https://master.php.net/note/edit/102285
Del: integrated  -- https://master.php.net/note/delete/102285/integrated
Del: useless     -- https://master.php.net/note/delete/102285/useless
Del: bad code    -- https://master.php.net/note/delete/102285/bad+code
Del: spam        -- https://master.php.net/note/delete/102285/spam
Del: non-english -- https://master.php.net/note/delete/102285/non-english
Del: in docs     -- https://master.php.net/note/delete/102285/in+docs
Del: other reasons-- https://master.php.net/note/delete/102285
Reject      -- https://master.php.net/note/reject/102285
Search      -- https://master.php.net/manage/user-notes.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.