Regex pattern help (I almost have it, just need a bit of expertise to finish it)

Posted by Mohammad on Stack Overflow See other posts from Stack Overflow or by Mohammad
Published on 2010-04-30T17:08:13Z Indexed on 2010/04/30 17:17 UTC
Read the original article Hit count: 191

Filed under:
|
|

I need to match two cases

js/example_directory/example_name.js 

and

js/example_directory/example_name.js?12345  

(where 12345 is a digit string of unknown length and the directory can be limitless in depth or not exist at all)

I need to capture in both cases everything between js/ and .js
and if ? exists capture the digit string after ?

This is what I have so far

^js/(.*).js\??(\d+)?

This works except it also captures

js/example_directory/example_name.js12345 

I want the regex to ignore that. Any suggestions?
Thank you all!

Test your patterns here

© Stack Overflow or respective owner

Related posts about regex

Related posts about .htaccess