3

How do I pattern match these URI's? I need to string match whatever characters are between the first and second slash (1) or any characters that are present after the first slash (2) or just /(3).

Note the trailing slash in the first example.

(1) /resource/_another-resource

(2) /_resource

(3) /

I have uri_resource = uri:match('^%/(.-)%/') which takes care of example 1 but will fail if no trailing slash is present.

BusterX
  • 125
  • 1
  • 7

1 Answers1

5

Try this pattern:

^/([^/]*)

It matches: a string starting with /, and then captures any characters that's not /.

Also note that / doesn't need to be escaped.

Yu Hao
  • 119,891
  • 44
  • 235
  • 294