Question

i have something like

some text here
<<<<<a href="/test.php?path=new&amp;id=221" style>>>>="display:block;">
some more text here

i am trying to match everything but <<<<<a href="/test.php?path=new&amp;id=221" style>>>>

i was also thinking something simple like [^<<<<<(.+)>>>>] would do the trick, but it seems like (.+) is not being considered

any ideas?

Was it helpful?

Solution

The [ and ] mean you're defining a character class.

If those < and > are really there, then:

var str = str.replace(/<<<<<(.+?)>>>>/, '');

The .+? means "a non-greedy match for one or more characters" (if we left off the ?, it would be greedy, and so might match some of the > following it and make the expression not match).

That will replace the first place that text appears with nothing, leaving you with just what's before and after it.

If that text may appear in more than one place, add the global flag to the regex:

var str = str.replace(/<<<<<(.+?)>>>>/g, '');

OTHER TIPS

There is a not operator if you want to match every line not having a certain pattern

^(?!<<<<<[^>]*>>>>)$

You will need the flag

RegexOptions.Multiline
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top