Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using regex to find specific files 1

Status
Not open for further replies.

bazil2

Technical User
Feb 15, 2010
148
0
0
DE
(Elementary user)

I would like to use two regular expression to find certain PDFs:

1) PDF files that begin with a 'P'
2) PDF files that only have numbers in the file name

Here are examples of some of my files:
Picture_001.pdf
Plans_001.pdf
1234567890.pdf
9987654432.pdf

Would the regular expressions be:
1) .P.*pdf
2) ^\d+$.pdf

Best regards
 
Hi

You forgot to specify what kind of regular expressions you need. Certain tools support different elements of different standards. Below I will suppose you want a PCRE.
bazil2 said:
1) .P.*pdf
[ul]
[li]The leading dot ( . ) is probably a typo there, intended to be a caret ( ^ ).[/li]
[li]Better anchor to the end of string too to avoid matching Picture_001.pdf.txt[/li]
[li]Better request a dot in front of the extension to avoid matching Picture_001.notpdf[/li]
[/ul]
This would result : [tt]^P.*\.pdf$[/tt]
bazil2 said:
2) ^\d+$.pdf
[ul]
[li]The dollar ( $ ) is in wrong position, should be at the end[/li]
[li]The dot should be escaped to interpret it literally, not as metacharacter[/li]
[/ul]
This would result : [tt]^\d+\.pdf$[/tt]


Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top