0

Tried negative look ahead but that doesnt seem to help

/^(?!www).(https:\/\/[^\s$\<]+)/g)

const regex = /(?!www).(https:\/\/[^\s$\<]+)/g;

[
  'https://google.fr',
  'https://www.google.fr',
  'www.google.fr',
  'google.fr',
].forEach((x) => {
  console.log(regex.test(x));
});
Orelsanpls
  • 22,456
  • 6
  • 42
  • 69

1 Answers1

0

You can use this since it's for validating links also :

const regex = /https?:\/\/(?!www\.)[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/;
    
[
  'https://google.fr',
  'https://www.google.fr',
  'www.google.fr',
  'google.fr',
].forEach((x) => {
  console.log(regex.test(x));
});
Oussail
  • 2,200
  • 11
  • 24