In a string I have somthing like this:
[select|blog]
Some text some text some text
[/select]
more text more text more text
[select|information]
Some text some text some text
[/select]
Now using preg_match I would like the function to:
- get the text between the [select] tags
- change it
- insert it back into the string
- remove the select tags
So in the end it will become something like this:
Changed text1 Changed text1 Changed text1
more text more text more text
Changed text2 Changed text2 Changed text2
Hope you guys can help me out. Thanks! 🙂
This regex will get you started
Put the option on that allows the dot . to match new line
The text inside the brackets is in group 1
I’m coming from the .NET world so I would tackle this with a function that I can let get executed after each match.
The input of this function is the match. Here you can get to group 1 if you need to access to it and rewrite or put your new content.
I just read in the comments that the equivalent in php is
preg_replace_callback()