简体   繁体   中英

RegEx: How to split url into two part with iis rewrite rule

so these is my url which i need to split into two part.

1) http://localhost:8800/

2) http://localhost:8800/About.aspx

3) http://localhost:8800/product.aspx?id=1&vref=201

4) http://localhost:8800/Contact.aspx

5) http://localhost:8800/Contact/india or http://localhost:8800/Contact/usa

see the above url and i want to split those url into two part using a single regex

1) first url has only one part 2) second url has two part like http://localhost:8800 and About.aspx

3) 3rd url has two part like http://localhost:8800 and product.aspx?id=1&vref=201

4) 4th url has two part like http://localhost:8800 and Contact.aspx

5) 4th url has two part like http://localhost:8800 and Contact/india or http://localhost:8800/Contact/usa

now tell me what regex i should apply in iis url rewrite rule which will split the above url in two part the way i describe here. please help me with exact regex which would work in iis rewrite rule pattern test.

Try this regex:

(https?:\/\/[^\/]+)\/(.*)

Group 1 is the first part. Group 2 is the second part.

It works by first finding http:// or https:// followed by a bunch of non-forward-slashes. It puts all that into group 1. Then, it looks for a forward slash. and finally, puts the rest of the string into group 2.

  • () is capturing group. The first pair of () is group 1, the second pair is group 2, and so on.
  • s? means that the s is optional
  • \\/ matches / literally. You can just write / in some flavours
  • [^] is a reverse character class. It will match anything except the characters inside it.
  • . matches everything except line terminators.
  • * means 0 or more times.

try it here: https://regex101.com/r/S9yg0C/2

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