Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Regex

  • 29-06-2010 06: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