Code Comments
Programming Forum and web based access to our favorite programming groups.Hi,
What I want is to split a string based on the following pattern
starts with '@{'
any number of characters can follow but when it finds a closing curly
bracket it should end. So the following expressions should match
@{x}
@{x_1_23}
@{y|hello|good|}
So lets say
$s = '@{x}+@{y12}=@{ans}fwf{sdfe@{d}wer32r3';
so this should be split in
+
=
fwf{sdfe
wer32r3
I've tried the following code but it doesnt work
<?php
$s = '@{x}+@{y}=@{ans}fwf{sdfe@{d}wer32r3';
$regex = '(@{).+}'; /* doesn't work */
$arr = split($regex,$s);
foreach ( $arr as $a)
echo '<br>' . $a;
?>
Also is there a way to store the patterns that have matched? @{x}, @{y12}
etc
Thanks
Post Follow-up to this messageYou are looking for: preg_match_all
Post Follow-up to this message"Olaf Schinkel" <blablabla@bluxxxxxxxx.de> wrote in message news:47e67793$0$23700$9b4e6d93@newsspool 2.arcor-online.net... > > You are looking for: > preg_match_all > Thanks! However, what would the regular expression be in this case? Regards
Post Follow-up to this messageFreelancer71 wrote: > "Olaf Schinkel" <blablabla@bluxxxxxxxx.de> wrote in message > news:47e67793$0$23700$9b4e6d93@newsspool 2.arcor-online.net... > > Thanks! However, what would the regular expression be in this case? http://www.greenhithe.org.uk/dev/preg_exp.php Code <?php $table = "@{x}+@{y12}=@{ans}fwf{sdfe@{d}wer32r3"; preg_match_all("|@{(.*)}|U",$table,$rows); //Loop through the table foreach ($rows[0] as $row){ //Returned all the contents echo $row."<br>\n"; } ?> With thanks to John Dunlop from comp.lang.php without whose help I would not know this Paul
Post Follow-up to this message<?php
$s = '@{x}+@{y12}=@{ans}fwf{sdfe@{d}wer32r3';
print_r(preg_split('/@\\{[^}]+\\}/',$s));
?>
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.