0

I have several regex patterns and i have to negate them all, so i am trying to build somo generic regex negate, something like /^(anypattern)/ but I am having troubles..

for example, I have this text: zzzzzAAAAA@AAAA_AAAzzzzzzAAAAA@AAAA.AAAggggggAAAAA@AAA.AAAooooooooo

and this pattern: [A-Z]+@[A-Z]+\\.[A-Z]{2,4}, I need something to negate this. I would get the an array with the following matches:

zzzzzAAAAA@AAAA_AAAzzzzzz , gggggg , ooooooooo

Note that AAAAA@AAAA_AAA was included only because this have a _ instead a dot

my regex are all simple, dont having any of these especial caracteres: \s,\t,\r,\n,\v,\f,\b,etc..

I tryed to solve it with negative lookarounds but without success

Matt Browne
  • 12,169
  • 4
  • 59
  • 75
leandromoh
  • 139
  • 6

1 Answers1

1

Try using a split with the regex exactly as you have it?

var input = "zzzzzAAAAA@AAAA_AAAzzzzzzAAAAA@AAAA.AAAggggggAAAAA@AAA.AAAooooooooo"
var output = input.split(/[A-Z]+@[A-Z]+\.[A-Z]{2,4}/)
console.log(output)

// outputs ["zzzzzAAAAA@AAAA_AAAzzzzzz", "gggggg", "ooooooooo"]

However, you may need to clean out empty elements, consider

var input = "AAAAA@AAAA.AAAzzzzzAAAAA@AAAA_AAAzzzzzzAAAAA@AAAA.AAAggggggAAAAA@AAA.AAAooooooooo"
var output = input.split(/[A-Z]+@[A-Z]+\.[A-Z]{2,4}/)
console.log(output)
// outputs ["", "zzzzzAAAAA@AAAA_AAAzzzzzz", "gggggg", "ooooooooo"]

After the setting the output variable, you can add this courtesy of this answer

output = output.filter(function(n){ return n != undefined && n.length})
// which outputs ["zzzzzAAAAA@AAAA_AAAzzzzzz", "gggggg", "ooooooooo"]
Community
  • 1
  • 1
Regular Jo
  • 5,190
  • 3
  • 25
  • 47