1

I have a script below:

<script src="http://localhost/folder/api/v1/shop/1?template=light" type="text/javascript"></script>

And need regular expression to detect this block: api/v{1-any number}/shop/{1-any number}

For example regular expression for this block: shop.load.v1.php :

/.*shop\.load\.([^/]+\.)?php/

Thanks.

1
  • I'm not sure I understand why you mentioned the regex for shop.load.v1.php? What does it have to do with detecting the block api/v{1-any number}/shop/{1-any number}? Commented Aug 22, 2013 at 7:02

2 Answers 2

5

You can use this pattern:

/api\/v(\d+)\/shop\/(\d+)/

It will match a literal api/v followed by one or more digits, followed by a literal /shop/ followed by one or more digits.

But this will match text like api/v00/shop/00. If you'd like to ensure the matched number is greater than or equal to 1, you can use this:

/api\/v([1-9]\d*)\/shop\/([1-9]\d*)/
Sign up to request clarification or add additional context in comments.

Comments

0

You can use:

/api/v[1-9]{1}\/shop\/[1-9]{1}/

This is if it can have only a single digit. For multiple digits:

/api/v[1-9]+\/shop\/[1-9]+/

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.