Jump to content

Removing a text delimiter like <><> ...


AndyB

Recommended Posts

[code]
<pre>
<?php

$tests = array(
'<><><>1<><><>',
'<><><>12<><><>',
'<><><>123<><><>',
'<><><>1234<><><>',
'in the middle <><><>1<><><> of a string',
'<><><>12345<><><>',
'<><><>a<><><>',
'<><>1<><>',
'<>1<>',
);

foreach ($tests as $test) {
printf(
'%-40s => %-40s<br/>',
$test,
preg_replace('/
( ### Begin capturing in \1
(?:<>){3} ### 3 instances of <>
) ### End capturing
(\d{1,4}) ### Capture 1 to 4 digits in \2
\1 ### Repeat match against \1
/x', '', $test)
);
}

?>
</pre>
[/code]

[tt]
<><><>1<><><>                            =>                                       
<><><>12<><><>                          =>                                       
<><><>123<><><>                          =>                                       
<><><>1234<><><>                        =>                                       
in the middle <><><>1<><><> of a string  => in the middle  of a string             
<><><>12345<><><>                        => <><><>12345<><><>                     
<><><>a<><><>                            => <><><>a<><><>                         
<><>1<><>                                => <><>1<><>                             
<>1<>                                    => <>1<>   
[/tt]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.