#1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2003
    Posts
    679
    Rep Power
    12

    It makes the matching at the last of the string


    I want to transform from this:

    Code:
    http://web.domain2.net/about-us/ggg/xxx/a/b/c/d/e/
    http://web.domain2.net/contact/stores/index.htm
    To this:
    Code:
    http://www.domain1.com/about-us/ggg/xxx/a/b/c/d/e/
    http://www.domain1.com/contact/stores/index.htm
    Using this regex:
    Code:
    ^(.*)\/(.*)\/(.*)
    And replace with:
    Code:
    http://www.domain1.com/$2/$3
    I receive this results:
    Code:
    http://www.domain1.com/e/
    http://www.domain1.com/stores/index.htm
    Do you have an idea how to make the matching at the beginning?

    Thanks
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,056
    Rep Power
    9398
    So are you redirecting all URLs or just some of them?
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2006
    Posts
    177
    Rep Power
    234
    you don't need a regular expression. just use simple split and join
    Code:
    $string = "http://web.domain2.net/about-us/ggg/xxx/a/b/c/d/e/";
    @l = split /\//,$string;
    $l[2] = "new.domain.com";
    print join("/",@l);
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2003
    Posts
    679
    Rep Power
    12
    I need to insert it into Apache conf.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2009
    Posts
    197
    Rep Power
    280
    Hello,

    How about using this?
    Code:
    :\/\/[^/]*\/([^/]*)\/([^/]*)\/([^/]*)
    Result:
    Code:
    http://www.domain1.com/ggg/xxx
    http://www.domain1.com/stores/index.htm
    Is this what you wanted?
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2003
    Posts
    679
    Rep Power
    12
    I tested it with Regular Expressions Tester and it isn't a valid regex
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2009
    Posts
    197
    Rep Power
    280
    Hello,

    Oh yeah, seems like I forgot to escape the "/"s in there.
    But please look away from that as I see a problem with the whole pattern now.
    I also see now that I misunderstood what you asked for when I gave you my solution earlier.
    Unfortunately, it does not seem like I am able to to assist you with the regex pattern after all.

    I think it will be much easier to just write a script to do it for you rather than use regex (unless someone else here knows a way).

    Sorry.

IMN logo majestic logo threadwatch logo seochat tools logo