2

In my Lua code I am receiving lot of URLs in form of string.

Example :

['http://www.abc.com/home/', 'http://www.abc.com/', https://www.xyz.com/v/123443/css/' , http://www.xyz.com/css/' ]

I want to fetch those URLs which are like :
https://www.xyz.com/v/123443/css/ where v is pre-defined string pattern and 123443 is random version generated to URL.

Please help me to fetch all URLs which are having that pattern into it like :
"/v/12332323/"

1
  • Did you search is SO for posts about pattern matching in Lua? There are several with lengthy explanations. Commented Feb 17, 2014 at 12:54

1 Answer 1

3
str = "https://www.xyz.com/v/123443/css/"    
print(str:match("https?://www%.[^/]+(/v/%d+/)%w+"))

Output: /v/123443/

This pattern matches strings that starts with http or https, and then ://, the website name starting with www., a /, the pre-defined string v and "random" numbers, followed by / and other stuff.

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

1 Comment

yes all sites are starting with www and they are ending like v/21323/css , v/12323/javascript , v/23232323/xml

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.