Regular Expressions: Match the documents ending with .pdf

Problem:

Create a regex expression that matches only documents ending with .pdf.

Output:






Solution:


I can't see an example importanter than this.

Step 1: Start with the ending. Tell the regex you want your the file to end with .pdf. To do that just type: \.pdf$ (^ indicates the beginning of the file, $ indicates the ending of the file).

Step 2: You don't care how the string begins and how many characters it will contain. So, you look for the regex note that indicates any regular character; it is already known \w.

Step 3: You don't know how many characters there are; it should be at least one character; the file cannot be ".pdf"; so for that you add + to the \w: \w+.

Step 4: Merge everything: \w+\.pdf$
That would capture for example: file_a_record_file.pdf

Step 5: The question is asking for file_a_record_file only! Not the pdf extension. No problem. Just do this: (\w+\)\.pdf$.
The paranthenties indicate that you're not interested in the .pdf thingy.

Final Answer: (\w+\)\.pdf$.


2 comments :

  1. office painting round rock With 30 years of experience, Kolor Pros Painting gives you the best results available. Our House Painters can handle any job, and can even repair drywall, or replace rotted wood trim. Call us today, and see what we can do for you!

    ReplyDelete
  2. Download offroad outlaws mod app is a new android game that challenges players to race through a variety of off-road environments, completing tasks along the way to earn rewards. The game is free to download and play, with no in-game ads or transactions required.

    ReplyDelete

Follow Me

If you like our content, feel free to follow me to stay updated.

Subscribe

Enter your email address:

We hate spam as much as you do.

Upload Material

Got an exam, project, tutorial video, exercise, solutions, unsolved problem, question, solution manual? We are open to any coding material. Why not upload?

Upload

Copyright © 2012 - 2014 Java Problems  --  About  --  Attribution  --  Privacy Policy  --  Terms of Use  --  Contact