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.
    – Oliver
    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.

1
  • yes all sites are starting with www and they are ending like v/21323/css , v/12323/javascript , v/23232323/xml Feb 17, 2014 at 12:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.