My favorite regex of all time
31–40 of 117 posts
Re: My favorite regex of all time
#32As someone who makes much of his living rehabilitating old perl scripts, please, if you must use such things, use them like this: [ -~] #match only printable characters It takes 5 seconds longer and with regexes, just knowing what the damn thing is trying to do is half the battle. When you use a regex, use a comment. Its the civil thing to do.
/x allows you to break up your regex into its component parts, one part per line, and then comment each part.
Here is what the manual says about /x:
/x tells the regular expression parser to ignore most whitespace that is neither backslashed nor within a character class. You can use this to break up your regular expression into (slightly) more readable parts. The # character is also treated as a metacharacter introducing a comment, just as in ordinary Perl code. This also means that if you want real whitespace or # characters in the pattern (outside a character class, where they are unaffected by /x), then you'll either have to escape them (using backslashes or \Q...\E ) or encode them using octal, hex, or \N{} escapes. Taken together, these features go a long way towards making Perl's regular expressions more readable.
Re: My favorite regex of all time
#33As someone who makes much of his living rehabilitating old perl scripts, please, if you must use such things, use them like this: [ -~] #match only printable characters It takes 5 seconds longer and with regexes, just knowing what the damn thing is trying to do is half the battle. When you use a regex, use a comment. Its the civil thing to do.
Unless you want to seem clever and impresse the PHB. It is the selfish (but smart) thing to do.
Re: My favorite regex of all time
#34It's clever, but it's also completely unreadable for anyone who didn't read this article. Regexes have serious maintainability issues as it is; let's not make it worse by putting clever tricks in them.
I don't understand why this is "completely unreadable". What else could this have been besides match the character range from space to tilde?
I don't think it is particularly bad though. It's just not the most trivial of regexes.
Re: My favorite regex of all time
#35Earlier quoted context omitted.
Thank you for that. You have no idea how annoying it is to port perl scripts from ASCII to EBCDIC when they do that kind of thing.
It's not an ASCII v EBCDIC thing, its an ASCII vs Unicode thing.
Re: My favorite regex of all time
#36[^ -~]
Not to be used in a serious program, but only in an editor (or maybe one-shot data massage perl scripts), to find possible errors or unexpected stuff.
Re: My favorite regex of all time
#37Re: My favorite regex of all time
#38Re: My favorite regex of all time
#39My favourite regex is actually: [^ -~] Not to be used in a serious program, but only in an editor (or maybe one-shot data massage perl scripts), to find possible errors or unexpected stuff.
Re: My favorite regex of all time
#40My favorite regex is the following, /^1?$|^(11+?)\1+$/ Which finds prime numbers. Although, I can't for the life of me think of a reason for using it. http://stackoverflow.com/questions/3296050/how-does-this-reg...