Regex gurus help the noob

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • madtwin
    Confirmed User
    • Aug 2009
    • 274

    #1

    Regex gurus help the noob

    I have url:

    http://gallys.40somethingmag.com/ima...=XXXXXXXXXXXXX

    I need regex to get url without NATS code:

    http://gallys.40somethingmag.com/ima...tyBlaze_28866/


    I have this regex: .*\?.*?
    but I end up with url like this:
    http://gallys.40somethingmag.com/ima...yBlaze_28866/?

  • Barry-xlovecam
    It's 42
    • Jun 2010
    • 18083

    #2
    Use a split
    Simpler to use a split; "\?"

    Code:
    #!/usr/bin/perl
    
    use strict;
    use warnings;
    
    
    my $URLstring = "http://gallys.40somethingmag.com/images/BettyBlaze_28866/?nats=XXXXXXXXXXXXX";
    
    our @url = split  /\?/, $URLstring;
    
    print $url[0] ."\n";
    
    exit;
    #output
    #12:24 AM barry@server:~/Desktop$ ./split.cgi
    #http://gallys.40somethingmag.com/images/BettyBlaze_28866/
    or regex then just substr 0, -1 ( in perl chop $url[0];)
    Last edited by Barry-xlovecam; 02-11-2013, 08:35 PM.

    Comment

    • madtwin
      Confirmed User
      • Aug 2009
      • 274

      #3
      Thank you

      Comment

      • hotbodybattles
        Registered User
        • May 2011
        • 28

        #4
        Regexbuddy is my best friend when writing perl and doing regex.. i used it more than anything when i was an automation engineer back at an old job.. now i'm writing perl code again at work and using it again... it's 40 bucks to buy though.. but you can probably torrent it.. but i didn't say that.

        but do a google search for Regexbuddy and the second hit down will be a thread on stackoverflow called "Is there anything like RegexBuddy in the open - Stack Overflow"

        that has some nice tools listed... if you still need em...

        regex'es can be a bitch.. or easy... sometimes you have to think outside the box and break down the string a bit more prior to regex'ing it..

        good luck

        Comment

        Working...