I have some code that is augmenting a regular expression by combining horizontal white-space and surrounding it in parentheses, unless it is already surrounded by non-backslashed parentheses. I have a piece of code that's working:
$regex_find = preg_replace('/(?<!\()[ \t]{2,}(?!\))/', '([ \t]{2,})', $regex_find);
However, for starters, the look-behind segnment, (?<!\(), should really allow for a literal left parenthesis, \(, but not a stand-alone left parenthesis, (.
Thanks
$s = '(\( ) b c d'; $s = preg_replace('/([^\t (])([ \t]{2,})([^\t )])/', '$1([ \t]{2,})$3', $s);Firstly, the replace does not allow for\(preceding the core string. And, yes, this left parenthesis would have to be single backslashed only. In addition, the right parenthesis needs to be tied into the left one. A proper solution of the above test string would be:(\(([ \t]{2,})) b c([ \t]{2,})d.