-1

Important: Without a not operator

I need to select everything that this regex doesnt match

 /^(http(s)??\:\/\/)?(www\.)?((youtube\.com\/watch\?v=)|(youtu.be\/))([a-zA-Z0-9\-_])+/gm
mouchin777
  • 1,428
  • 1
  • 31
  • 59

1 Answers1

0

Why don't you just use the NOT operator?

!"https://www.youtube.com/watch?v=OsCfufAp2tM".match(/^(http(s)??\:\/\/)?(www\.)?((youtube\.com\/watch\?v=)|(youtu.be\/))([a-zA-Z0-9\-_])+/gm)

Returns false

!"randomwords".match(/^(http(s)??\:\/\/)?(www\.)?((youtube\.com\/watch\?v=)|(youtu.be\/))([a-zA-Z0-9\-_])+/gm)

Returns true

EDIT: looks like you won't use the NOT operator, so another way of doing is reverse the regex with ?! operator like so:

/^(?!(http(s)??\:\/\/)?(www\.)?((youtube\.com\/watch\?v=)|(youtu.be\/))([a-zA-Z0-9\-_])+)/gm
stalker2106
  • 118
  • 9