2

I have a url route I want to match only has url parameter

router.get('/:id',function(req,res,next){
}

Now the problem is other url like test, favicon all matches this path. I want to match only url path which is hash like and other related hash strings which will be random.

%242a%2410%24mbh0scotTihKwL69eKwVBuSoAShai4Qo8yY0HLPRlh0Pq0ospfAcm 

I have tried with regular expression but , i dont seem to get my regex to match.

[a-z0-9][-!$%^&*()_+|~=`{}\[\]:";'<>?,.\/]{50,}$

I want to match any string with special characters with length of 50 and above .Can anyone help me ? Thank you

1
  • I think you wanted to write ^[-a-zA-Z0-9!$%^&*()_+|~=`{}\[\]:";'<>?,.\/]{50,}$ or ^[a-zA-Z0-9][-a-zA-Z0-9!$%^&*()_+|~=`{}\[\]:";'<>?,.\/]{49,}$ Commented Oct 10, 2016 at 10:43

1 Answer 1

1

I want to match any string with special characters with length of 50 and above

In this case, you may use the following pattern:

^[-a-zA-Z0-9!$%^&*()_+|~=`{}\[\]:";'<>?,.\/]{50,}$

However, if you need to require the first char to be an ASCII letter or digit, you can do it either by rewriting the pattern as this one:

^[a-zA-Z0-9][-a-zA-Z0-9!$%^&*()_+|~=`{}\[\]:";'<>?,.\/]{49,}$
 ^^^^^^^^^^^                                           ^^^^ 

Or by using a lookahead (so as to keep 50 as the min argument) (see this demo):

^(?=[a-zA-Z0-9])[-a-zA-Z0-9!$%^&*()_+|~=`{}\[\]:";'<>?,.\/]{50,}$

In all the cases, the main point is that you need to adjust the limiting quantifier at the end / shift the character classes boundaries and make sure you use ^, the start of string anchor if your substring is at the start of the string. If it is not, you should remove it.

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

Comments

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.