-2

Please advice a regular expression to find all string which are not ended with ".pdf". So, it should find stings "some string" and "some stringpdf", but not the strings like "some string.pdf"

Thanks, Aleksey Asiutin

Marc
  • 3,683
  • 8
  • 34
  • 48
aasiutin
  • 210
  • 2
  • 6

2 Answers2

0

If you are going to test individual string's you can use this regex

/^(?!.*\.pdf$).*$/

If there are multiple string's to be matched within the string,you can use

/(\s|^)(?![^\s]+\.pdf(\s|$))[^\s]+/
Anirudha
  • 32,393
  • 7
  • 68
  • 89
0

here's the regex

/^(?!.*\.pdf$).*/

example:

var r =  /^(?!.*\.pdf$).*/;
r.test("some string");     //true
r.test("some stringpdf");  //true
r.test("some string.pdf"); //false

in actually, I recommend the suggestion from @Nannuo Lei.

Rain Diao
  • 926
  • 6
  • 12