Marsh Posted June 29, 2015 Author Share Posted June 29, 2015 Help the owners fix the url matching code! Write your own regex!! Winner will receive bragging rights for life. There is a template for urls in my regexr link.Contest ends on Monday the 6th.Scoring:+ 1 point for each matched url- 1 point for each matched url that should not be matched (see template)If tie, shortest regex.Multiple submissions are allowed. Any copy pastes from online will be removed from the contest.Go!* * *First submission to get the ball rolling1st```(http://|www\.)[^ \t\n]+```2nd```(http://|www\.|https://|ftp:)[^ \t\n]+```[Template and my submission link. Click Me!](http://regexr.com/3b9u8)**Rankings:**1st. PandaCoder - 36 points.2nd. TehDoug- 24 points.3rd. Lemon- 24 points.4th. Marsh - 11 points.5th. creatorfromhell - 5 points. Link to comment Share on other sites More sharing options...
YourBestNightmare Posted June 29, 2015 Share Posted June 29, 2015 Regex contest here? It will be max 2 or 3 participants imo. Link to comment Share on other sites More sharing options...
Lemon Posted June 29, 2015 Share Posted June 29, 2015 ```((https?|ftp):\/\/(([^.\/\s#?]+?)(?=\.)([^\s]+)))```I still need to perfect this… It's almost there, just one more rule... I'm heading to lunch, I'll perfect this later. Link to comment Share on other sites More sharing options...
deathtaker26 Posted June 29, 2015 Share Posted June 29, 2015 I had to look up with RegExr, I felt like a retard when I realized it was an abbreviation for Regular Expressions -Y- Link to comment Share on other sites More sharing options...
BeNjO Posted June 29, 2015 Share Posted June 29, 2015 ```text.replace(/((https?|ftp):\/\/(([^.\/\s#?]+?)(?=\.)([^\s]+)))/g, '[$3]($1)')```Lemon stole my attempt, thanks… Link to comment Share on other sites More sharing options...
Lemon Posted June 29, 2015 Share Posted June 29, 2015 Sure, "stole" your attempt that you did 50 minutes later… Link to comment Share on other sites More sharing options...
BeNjO Posted June 29, 2015 Share Posted June 29, 2015 I posted it in the mass Skype chat and you stole it from there, either way i was close just need to add 1 more rule just heading to lunch. Link to comment Share on other sites More sharing options...
Lemon Posted June 29, 2015 Share Posted June 29, 2015 There's a mass skype chat? Link to comment Share on other sites More sharing options...
BeNjO Posted June 29, 2015 Share Posted June 29, 2015 That's right, play dumb. Either way I did most of the work, go finish it… Link to comment Share on other sites More sharing options...
Lemon Posted June 29, 2015 Share Posted June 29, 2015 Well, I give up trying to get my last rule in place; it was for if you have a slash immediately after a dot. Whatever, it's perfect otherwise:```text.replace(/((https?|ftp):\/\/(([^.\/\s#?]+?)(?=\.)([^\s]+)))/g, '[$3]($1)')```http://regexr.com/3b9taLonger than Marsh's, but it covers more rules; less matches made on invalid URLsNot sure what my score is, since I can't figure out how Marsh got his score from his own scoring system… Link to comment Share on other sites More sharing options...
Marsh Posted June 29, 2015 Author Share Posted June 29, 2015 Good chance my score is wrong, I just took the amount regexr said it matched then -1 each one it shouldnt have matched. But I counted quickly so I may be off. Link to comment Share on other sites More sharing options...
Chief Posted June 29, 2015 Share Posted June 29, 2015 For the public record, I'm Lemon, attribute my effort to Chief, now. Link to comment Share on other sites More sharing options...
creatorfromhell Posted June 29, 2015 Share Posted June 29, 2015 Well, my regex started off looking nice….it has become unsightly, and I don't even expect to win so x3.```((((https?|ftps?)+:\/\/)+(www.)?)+(\.(?!www\.)|[-a-zA-Z0-9_@~:/?#\[\]@!$&'()*+;=]|[^\x00-\xFF]|[^\u0000-\u0080]|[\u0600-\u06FF])+((\.+(com|net|ws|de|mp|bar|[^\x00-\xFF]|[^\u0000-\u0080]|[\u0600-\u06FF]))|:[0-9]|\.[0-9]{3}|\.[0-9]{2})+((\/(?!\.))+([-a-zA-Z0-9_@~:/?#\[\]@!$&'()*+;=]|[\x00-\xFF]|[\u0000-\u0080]|[\u0600-\u06FF]))?)```I didn't add a full list of TLDs to the example, because the here's the full list… http://data.iana.org/TLD/tlds-alpha-by-domain.txthttp://regexr.com/3ba1q Link to comment Share on other sites More sharing options...
pandacoder Posted June 30, 2015 Share Posted June 30, 2015 So I went and created a testing system for our little pet project that outputs if you've passed test cases or failed them, which you can find [here](http://live.pandacoder.info/scripts/urlregextest.html).(if you didn't click "here": [http://live.pandacoder.info/scripts/urlregextest.html](http://live.pandacoder.info/scripts/urlregextest.html))**Something to note**: RegExr doesn't do the job properly, not sure why (though it comes close, but in my tester using the regular RegExp JavaScript object the Arabic URL is properly handled, as for some reason RegExr cuts off because of the \n character, which is part of \s).**Score**:- if you were supposed to match it and you did, -1 point- if you were not supposed to match it and you did, -1 point- if it was a custom test that I added it does not affect your score (these are marked [OPTIONAL], and should be located at the bottom of all the test cases)**Clarifications I made**:One thing I did do is say that a partial match doesn't count, only full matches: e.g. in "http://google.com /querystring", "http://google.com" is a valid URL, but the whole thing is not.The reason I say that is is the appropriate way to go about doing this is because the purpose of our RegEx is to parse URLs in chat, which will most likely have other spaces.Instead of leeway which I just reasoned to give, a restriction should be that your RegEx must function without the use of ^$ around it, because if it requires that it's no longer realistic (^some regex$ matches from the start to the end of the string, unless you're using a RegEx engine that splits on new lines), and since from what I can tell the JavaScript RegEx engine handles it as from the beginning to the end of the string, and $ does not match line breaks.**By the way, my entry (388 characters, but given the clarifications I made above it matches every single test case that is currently present):**```((?:(?:https?|ftp):\/\/)((?:[^\s:@]+(?::[^\s@]+)@)?(?:(?:(?:(?!(?:22[4-9]|2[3-5][0-9]|127|10|0))(?:2(?:[0-1][0-9]|2[0-3])|1[0-9]{1,2}|[1-9][0-9]|[1-9]))\.)(?:(?:2(?:[0-4][0-9]|5[0-5])|1[0-9]{1,2}|[1-9][0-9]|[1-9])\.){2}(?:(?:2(?:[0-4][0-9]|5[0-4])|1[0-9]{1,2}|[1-9][0-9]|[1-9]))|(?:(?!.+\.\/)(?:[^\s\-\.](?:(?!\-\-+)[^\s\.]*?[^\s\-])?\.)+[^\s\.\-0-9:\/]+))(?::[0-9]{1,5})?(?:\/[^\s]*)?))```@Marsh: I'll be on the shoutbox sometime in the morning if you have any comments about anything I wrote here. Link to comment Share on other sites More sharing options...
Marsh Posted June 30, 2015 Author Share Posted June 30, 2015 That is amazing panda, thanks a lot. I have updated the scores on the first page.**Rankings:**1st. PandaCoder - 36 points.2nd. TehDoug- 24 points.3rd. Lemon- 24 points.4th. Marsh - 11 points.5th. creatorfromhell - 5 points. Link to comment Share on other sites More sharing options...
pandacoder Posted June 30, 2015 Share Posted June 30, 2015 Thanks Marsh.Also if anyone wants to add test cases just let me know. You can find the format of the test cases in the source for that page. Link to comment Share on other sites More sharing options...
Marsh Posted July 11, 2015 Author Share Posted July 11, 2015 PandaCoder is the winner!!!!Grats to him and thanks to all who entered!If you dont know Regex its a great thing to learn, it can be a massive timesaver in your daily life. Link to comment Share on other sites More sharing options...
BeNjO Posted July 11, 2015 Share Posted July 11, 2015 Gratis panda, glad I actually positioned ha-ha Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now