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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Regex

  • 29-06-2010 5: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,306 ✭✭✭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,306 ✭✭✭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,414 ✭✭✭✭Trojan


    You might find this RegEx tester useful.
    HTH


Advertisement