Hi,
I am trying to write a regex to capture anything but < followed by upper case letters followed by >. For example
<YEAR>-<MONTH>-<DAY> => I want to capture - and replace it with ' "-" ' so the output string should be <YEAR> "-" <MONTH> "-" <DAY>
<YEAR>.<MONTH>.<DAY>. => output should be <YEAR> "." <MONTH> "." <DAY> "."
I have tried the following
[^<][^A-Z]*[^>]
[^<[^A-Z]*^>]
(^(<[A-Z]*>)
I am not able to figure out how exactly I will be able to capture and replace it. I can do it in otherway by finding indexes of string literals and then doing math but that is not a clean way to do this.
Any help to write this will be appreciated.
Thank you.
Regex to capture anything but <[A-Z]*>
Moderator: General Moderators
$string="I assume your content string here";
Not sure of this since I dont have data to test, but I hope a bit of permutations can possibly make a solution.
Let us know if this helped.
Code: Select all
$pattern ="/(<.[^A-Z]+>)/s";
$content=preg_split($pattern, $string, -1,PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);Let us know if this helped.