Regular Expression, need help |
[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
[eluser]pistolPete[/eluser]
Try this: Code: // you probably have a typo there '... is {constant1} and ...'
[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
[eluser]pistolPete[/eluser]
Okay, try this: Code: $subject = 'my name is {constant1} any I am looking for {constant2}';
[eluser]gungbao[/eluser]
Works finest! PistolPete, once again - very great help from your side!
[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. |
Welcome Guest, Not a member yet? Register Sign In |