-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

3
  • If that's all you need, you can use a regexp to find .pdf-ended strings, and then reject them when they match, and accept the rest Commented Feb 7, 2013 at 14:32
  • 2
    @NannuoLei Don't even think about abusing regex for this purpose. Commented Feb 7, 2013 at 14:39
  • @Jack you're right, regexp is too mucch for such small task, thank you for pointing it out. Commented Feb 7, 2013 at 18:51

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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]+/

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.