#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2018
    Posts
    3
    Rep Power
    0

    RegEx Parse URL Into Groups Based On Text Slash


    I am trying to parse the below URL into 3 different sections based on the word/ before the id and capture till the next /.


    Code:
    https://www.domain.com/word1/45611-sdff-78df-1234-4sdaf89sd/word2/61237-sdff-78df-1234-4sdaf89sd/word3/99812-sdff-78df-1234-4sdaf89sd/garbage
    Group1: 45611-sdff-78df-1234-4sdaf89sd
    Group2: 61237-sdff-78df-1234-4sdaf89sd
    Group3: 99812-sdff-78df-1234-4sdaf89sd


    Thank you!
  2. #2
  3. Impoverished Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,834
    Rep Power
    9646
    Are you literally parsing that entire string? What parts are fixed and what parts are variable? Presumably it's "fixed://fixed/variable/GUID/variable/GUID/variable/GUID/variable".
    Or is this part of some URL rewriting you want to do? Apache or IIS?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2018
    Posts
    3
    Rep Power
    0
    Originally Posted by requinix
    Are you literally parsing that entire string? What parts are fixed and what parts are variable? Presumably it's "fixed://fixed/variable/GUID/variable/GUID/variable/GUID/variable".
    Or is this part of some URL rewriting you want to do? Apache or IIS?
    The only pieces that change are the GUID IDs. The fixed words will always be the same in every URL. I was thinking that is what I could do the group sorting on perhaps?
    "fixed://fixed/fixedword1/GUID/fixedword2/GUID/fixedword3/GUID/variable"
  6. #4
  7. Impoverished Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,834
    Rep Power
    9646
    If the fixed words are never going to change then you don't need regular expressions: you can use plain string functions to extract the portion of the URL string at the positions you know where the GUIDs are. The only variable part is at the end after the GUIDs so it doesn't matter.

IMN logo majestic logo threadwatch logo seochat tools logo