简体   繁体   中英

Regex to find a pattern of string between slashes

I'm looking for the right way to build the regex for this:

I have these sites and I need cut the word string or whatever have between slashes. Using the https://regexr.com/

I had this result. Someone can help me?

http://example.com/string/anotherThings
http://example.com/string/anotherThings
http://example.com/string_string/anotherThings

例

  • If there are multiple slashes in the url, do you wish to retrive the shortest part or the whole part, like this: https://test.com/page/number/1 , which one do you actually want?
  • If it's page/number , the regex should be (?<=\\/)[\\w_\\]+(?=\\/)
  • If it's page , number , try (?<=\\/)[\\w_]+(?=\\/)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM