1

I am trying to look for files with ".js", ".less", ".jsp", and ".png" files while also checking for them in many different directories for example "/MyProject/public/someSecurePage.jsp", "/MyProject/public/js/page/SecuredPage1/", "/MyProject/public/js/page/SecuredPage2/", "/MyProject/public/less/page/SecuredPage1/", etc

I am using the someString.macthes(regexString)

Right now I have 2 separate regexes, but I am not sure they are correct:

File exts

.*?\\.(jsp|less|css|png|js)$

Directories/Files

EDIT1:

.*?\\.(/MyProject/public/someSecurePage.jsp|/MyProject/public/js/page/SecuredPag‌​e1/|/MyProject/public/js/page/SecuredPage2/|/MyProject/public/less/page/SecuredPa‌​ge1/)

EDIT1:

Another issue I am looking at is that this does not seem to look at /MyProject/public/js/page/SecuredPage2/securedPage2.js is not getting read correctly, my if statement is coming to false with this check.

My issue is that I am not actually sure that my files/ directories one is correct, because going through an if statement trying to match a directory, comes to false. I am new to using regular expressions

8
  • I don't think the double forward slashes // are necessary, you should be able to just use a single slash. .*?\\.(/MyProject/public/someSecurePage.jsp|/MyProject/public/js/page/SecuredPage1/|/MyProject/public/js/page/SecuredPage2/|/MyProject/public/less/page/SecuredPage1/)$ I could be wrong though. Commented Mar 12, 2014 at 4:26
  • I wasnt sure because I thought one slash was an escape character, that is kinda a reason I am asking Commented Mar 12, 2014 at 4:27
  • 1
    Only the backslash "\" is an escape character. Commented Mar 12, 2014 at 4:28
  • Okay I will try out the single forward slash Commented Mar 12, 2014 at 4:29
  • 1
    Ok, I posted an answer with a fully modified regex. See if that helps. Commented Mar 12, 2014 at 4:48

1 Answer 1

2

I think this is the full regex you want. If you only want to find files in "/MyProject/public/someSecurePage/", "/MyProject/public/js/page/SecuredPag‌e1/", "/MyProject/public/js/page/SecuredPage2", and "/MyProject/public/less/page/SecuredPa‌​ge1/" with extensions "jsp", "less", "css", "png", and "js".

^.*(/MyProject/public/someSecurePage|/MyProject/public/js/page/SecuredPag‌ e1|/MyProject/public/js/page/SecuredPage2|/MyProject/public/less/page/SecuredPa‌​ge1)/.*\\.(jsp|less|css|png|js)$

^.* means match anything 0 or more times starting from the beginning (honestly you may not even need this part for it to work). ^ Means beginning, $ means end.

/.*\\. means match forward slash anything dot. E.g. /MyProject/public/less/page/SecuredPa‌​ge1/qwerty. would be a match if we left out (jsp|less|css|png|js)

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

4 Comments

if you dont mind, would you be able to explain how the characters before the '( )' work?
Awesome. Sure, before which set of '()'?
both if you dont mind. from my understanding I think the first one matches any sequence, but I am not totally sure
No problem. Let me know if I need to explain it any better.

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.