-2

I'm looking for a regex that will only match when there is NO extension in a file name.

test.doc = no match
testaaa = match

I can posititely find the '.' with /. but how can I negate this? I tried using (?!.) but I get a match on every character of the file name.

Thanks

1 Answers1

1

I'd check that the file doesn't have any dots with ^[^.]*$:

var patt = new RegExp("^[^.]*$");

console.log(patt.test('test.doc'));
console.log(patt.test('testaaa'));
Obsidian Age
  • 41,205
  • 10
  • 48
  • 71