My current task involves extracting strings between two specified tags. Here is the code that accomplishes this:
if (text.toLowerCase().indexOf("[CUSTOMTAG]") >= 0) {
_data = /\[CUSTOMTAG](.*?)\[\/CUSTOMTAG]/g.exec(text);
if (_data[1] && _data[1].length > 0) {
const data = _data[1];
}
}
However, I encountered an issue when the string between the tags contains special characters like:
[CUSTOMTAG]this is some
[/ru ugly content here[/CUSTOMTAG]
When this occurs, I receive an exception stating Cannot read property '1' of null
due to parsing failure.
Is there a way to bypass escaping characters within the string?