Hi,
I have a tricky RegEx I am trying to get to the bottom of...
I want to look at the value of every 12th character, then backtrack and replace the LAST space I find with a \n. (So it backtracks from the 12th char back to the previous space and subs that) For example...
"The quick brown fox jumps over the lazy brown dog"
Becomes
"The quick\nbrown fox\njumps over\nthe lazy\nbrown dog"
The closest I can get is to do this:
if (strlen ($annotate)>11)
{
$annotate=preg_replace("/(.*)?( )/","$0\n",$annotate);
}
But this only does the last space of each string fed into it. I know using the if statement is the wrong approach, but I'm very stuck here.
Any help greatly appreciated
Thanks
I have a tricky RegEx I am trying to get to the bottom of...
I want to look at the value of every 12th character, then backtrack and replace the LAST space I find with a \n. (So it backtracks from the 12th char back to the previous space and subs that) For example...
"The quick brown fox jumps over the lazy brown dog"
Becomes
"The quick\nbrown fox\njumps over\nthe lazy\nbrown dog"
The closest I can get is to do this:
if (strlen ($annotate)>11)
{
$annotate=preg_replace("/(.*)?( )/","$0\n",$annotate);
}
But this only does the last space of each string fed into it. I know using the if statement is the wrong approach, but I'm very stuck here.
Any help greatly appreciated
Thanks
Last edited: