Richard
Richard

Reputation: 826

RegEx How to get everything after a /

I'm currently using http://www.regexr.com/ and the Strings I'm trying to parse through are in the format of 133a1d6a-f4fa-49ba-928d-0f4c943ce5d3/File-20140805-013806693.pdf.

I'm trying to get only the portion after the / and before .pdf.

My current regex pattern I have is: /\/([A-Za-z0-9-])+/g

which gives me: /File-20140805-013806693

How do I make the pattern omit the / AND the file type only matching File-20140805-013806693

My next step is to put this into java code while iterating through a loop of these Strings.

Any help would be appreciated!

Upvotes: 2

Views: 133

Answers (3)

Elkfrawy
Elkfrawy

Reputation: 353

Try using:

(?<=\/)[A-Za-z0-9-]+

Upvotes: 2

enrico.bacis
enrico.bacis

Reputation: 31494

You can use a combination of lookahead and lookbehind:

/(?<=\/).*?(?=\.pdf)/g

You can test it here.

Upvotes: 0

progrenhard
progrenhard

Reputation: 2363

This seems to be what you are looking for.

.*\/([^./]+).[\w\d]+$

Regular expression visualization

Debuggex Demo

This regex gets all the file extensions if you just want .pdf do this.

.*\/([^./]+).pdf$

Upvotes: 1

Related Questions