Regular Expression, need help - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Regular Expression, need help (/showthread.php?tid=23898) |
Regular Expression, need help - El Forum - 10-25-2009 [eluser]gungbao[/eluser] Hi there, stucking in timeline and regex-world, I kindly ask you for some help: Have PHP-String: $s = "my name is {constant1} any I am looking for {constant2}"; Want Regex to retrieve: Array('constant1', 'constant2') preg_match("/\{(.*)\}/",$s, $captures); give silly answers. Could pls. someone help me. Great thanks in advance, Cheers Chris Regular Expression, need help - El Forum - 10-25-2009 [eluser]pistolPete[/eluser] Try this: Code: // you probably have a typo there '... is {constant1} and ...' Regular Expression, need help - El Forum - 10-25-2009 [eluser]gungbao[/eluser] Sorry, I did not ask that correctly: {constant1}, {constant2}, ... {constantN} are ment as placeholders in ANY string content, similar to a simplified template language. I am looking to grep all that tokens within the {...} with a regular expr. Hope its clarified better, now Greetz Chris Regular Expression, need help - El Forum - 10-25-2009 [eluser]pistolPete[/eluser] Okay, try this: Code: $subject = 'my name is {constant1} any I am looking for {constant2}'; Regular Expression, need help - El Forum - 10-25-2009 [eluser]gungbao[/eluser] Works finest! PistolPete, once again - very great help from your side! Regular Expression, need help - El Forum - 10-25-2009 [eluser]BrianDHall[/eluser] Regex is very powerful yet can be such a pain. For a really great reference site check out: http://www.regular-expressions.info/ Also I highly recommend having an editor that allows regex search/replace functions, as it is so much easier to paste example text into a text file and test inside the editor than it is to try running it through PHP first. |