0👍
You could use something like (considering string
is your text):
True:
!!string.match(/<[^>]*>.+<[^>]*>/)
False:
!!string.match(/<[^>]*><[^>]*>/)
This would work for your cases but if it’s something more complicated you would need to use recursive patterns (which afaik are not available in JS) – if you want to use strictly regular expressions.
For the exact use cases – something like this should work:
const rules = [
[/<right>.+(?<!>)<[^>]*>/g],
[/<center>.+(?<!>)<[^>]*>/g],
[/<left>.+(?<!>)<[^>]*>/g],
[/<a\s+[^>]*>.+(?<!>)<[^>]*>/g],
[/<[^>]*>.+(?<!>)<[^>]*>/g],
];
Source:stackexchange.com