Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.
Hi all, please see this major site announcement: https://www.boards.ie/discussion/2058427594/boards-ie-2026

Regex

  • 29-06-2010 05:23PM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 Posts: 1,346 ✭✭✭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, Registered Users 2 Posts: 1,346 ✭✭✭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, Registered Users 2 Posts: 16,415 ✭✭✭✭Trojan


    You might find this RegEx tester useful.
    HTH


Advertisement