Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Regex

Options
  • 29-06-2010 6:23pm
    #1
    Registered Users Posts: 302 ✭✭


    I want to implement a regex to force a blank value or a web-address, non-case-sentitive, starting with either http:// or https://. I used to know w bit of regex, but I dont want to revisit just to crack this. Perhaps someone can spit this off the top of their head.

    "http://*.*", where I want the prefix followed by domething with a full stop and something on either side of it, and no spaces.


Comments

  • Registered Users Posts: 1,228 ✭✭✭carveone


    BlueSpud wrote: »
    I want to implement a regex to force a blank value or a web-address, non-case-sentitive, starting with either http:// or https://. I used to know w bit of regex, but I dont want to revisit just to crack this. Perhaps someone can spit this off the top of their head.

    "http://*.*", where I want the prefix followed by domething with a full stop and something on either side of it, and no spaces.

    Er. Not quite sure exactly what you want but maybe:

    tolower(str) ~ /^https?:\/\/[^:space:]+\.[^:space:]+$/

    That's awk. In perl I'd put a i after the regexp instead of using tolower.


  • Registered Users Posts: 1,228 ✭✭✭carveone


    Or

    /^https?:\/\/[\w\-]+(\.[\w\-]+)+$/

    I'd forgotten that Perl has \w for "alphanumeric + underscore" and you can nest pluses. Of course this will match:

    You could then have to add more to match:
    Ie: it is not trivial to do...


  • Registered Users Posts: 16,413 ✭✭✭✭Trojan


    You might find this RegEx tester useful.
    HTH


Advertisement