-1

I want to check if url is valid, what is the correct regexp to do that in lua? I tried regexp like this

string.match('https://stackoverflow.com/', '[a-z]*:\/\/[^ >,;]*')

but getting error

invalid escape sequence near ''[a-z]*:\/'

Update:

string.match('https://stackoverflow.com/', '[a-z]*://[^ >,;]*')

is correct answer

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
Sergey Lapin
  • 1,008
  • 3
  • 12
  • 21

1 Answers1

5

The error is fairly clear: \/ is an invalid escape. You don't need to escape /, as it's not a special character in Lua patterns (check the list of "magic" characters) and removing the escape should work: string.match('https://stackoverflow.com/', '[a-z]*://[^ >,;]*').

Paul Kulchenko
  • 25,884
  • 3
  • 38
  • 56