0

I write a RegExp for validate a file URL

file:/{2,3}[a-zA-Z0-9]*\\|?/.*

for URL like

file:/D:/workspace/project/build/libs/myjar-1.0.jar

But doesnt work, am looking for a pattern that matches only URL like this,no other.

Pattern Will return false URLs like

file:/workspace/project/build/libs/myjar-1.0.jar and file:/D:/workspace/project/build/libs/myjar-1.0 are will not match

please help

3
  • What context is this?? Because if it has no context to match it just /file\:.*/i Commented Nov 28, 2013 at 5:07
  • Your range {2,3} doesn't even match this. Commented Nov 28, 2013 at 5:16
  • file:/[a-zA-Z0-9]*/.* Commented Nov 28, 2013 at 5:25

2 Answers 2

1

Complete question rewrite

Given the OP's updated criteria, the regex you're looking for is file\:\/\w\:\/[^\s]*\.jar; ensure you enabled g (global) and i (case-insensitive) modifiers.

See a working example on Regex101

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

7 Comments

Saw that, hence my stating that given your context, @JorgeCampos answer is the most suitable. If you have other criteria (e.g. disallow spaces, require colon) that obviously changes the expression.
problem is when i validate the url @JorgeCampos expression is return true when the url is 'file:/workspace/project/build/libs/myjar-1.0.jar' and 'file:/workspace/project/build/libs/myjar-1.0'
I see your updates to the question, standby while I edit this answer to reflect the 'false' matches.
Done - see the new answer.
but it doest work on Chrome :RegExp tester extension .See scrnprt prntscr.com/275x8o
|
0

If there is no context or rule your regex should be:

/file\:.*/i

See it here: http://regex101.com/r/yY5xG6

1 Comment

When you sai like this, I ask Like this what? same path? same number of directories? Just from D: directory? Just *.jar files? You see, still much vague

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.