Can anyone see why this is giving an Invalid regular expression: Invalid group error?
text.replace(/(?<!br|p|\/p|b|\/b)>/g, ">");
This one is OK:
text.replace(/<(?!br|p|\/p|b|\/b)/g, "<");
So, I'm not sure where I'm going wrong with the first one (>).
Here's a fiddle with an example.
JavaScript does not support lookbehinds. Here is one way you can get the same behavior:
text = text.replace(/(br|p|\/p|b|\/b)?>/g, function($0, $1){
return $1 ? $0 : ">";
});
This approach comes from the following blog entry: Mimicking Lookbehind in JavaScript
Here is an updated fiddle.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With