Home > Back-end >  Regex or without grouping
Regex or without grouping

Time:02-23

I want to get the thread-id of an url via regex.

The Url can have these states:

  1. https://mypage.com/threads/an-example-thread/
  2. https://mypage.com/threads/an-example-thread/page-1
  3. https://mypage.com/threads/an-example-thread

My pattern . /threads/(. )/. covers the first two options. Now I need a pattern, that also covers option 3. . /threads/(. )(/. |$) works. But I use the first group to get the tread-id/name. So how is is possible to create an or-pattern without grouping?

CodePudding user response:

As mentioned in the comments, try to use /threads/([^\/]*), that will match all 3.

  • Related