5 ms·
I think the goal should be clarity, not conservation of characters. And I think the escaped dot is clearer (the author's intent is obviously to include a dot in
by eli 14y ago
I think the goal should be clarity, not conservation of characters. And I think the escaped dot is clearer (the author's intent is obviously to include a dot in the range).
I do think it's funny that you said "There isn't and shouldn't be any hard fast rule for this" and then one comment later said my approach is "wrong" :) (EDIT: oops, that wasn't you -- Sorry!)
- logn 14y agoIt's only clear for people who don't really understand regexes. For people with knowledge of them, it's more ambiguous as to whether a slash is being matched or used to escape. It reminds me of commenting the end of your for loops, } //end for ... it's clear for people who come from Python and don't know Java but that's not who we should be helping.
- deleted 14y ago[deleted]
- Firehed 14y agoAre you writing this for yourself or to share? If the latter, optimize readability for people who don't understand regexes. As for commenting the end of loops - that too just improves readability, especially in long functions. If your editor doesn't show invisible characters, it can be easy to lose track if some indent is part of the 'i' loop or the 'j' loop, for example (yes, that can indicate a bigger problem, but that's not the point. I'm talking about real-world code, not idealistic academic nonsense)
- hkolek 14y agoWhy? So my grandma can read my code? That's not the way to enlightenment if you program in a professional setting.
- 6ren 14y agoIt seems that statement wasn't a hard and fast rule. ba dum tish I think everyone should do what they want, including telling others what to do, hypocritically. I prefer not to escape dots in char classes, because escapes make it less readable for me. I know this involves a more complex rule, for where one need not escape, but somehow my mind easily treats character classes as a special case region.
- ralph 14y agoIt's not necessarily your choice. [\.] in sed is a two-character character class.
- ralph 14y ago> you said "There isn't and shouldn't be any hard fast rule for this" No I did not. You're confused as that was someone else. :-) Do not needlessly escape. Only escape what that flavour of syntax needs you to do. What you may think is a needless escape may actually give different behaviour. $ sed 's/[x\.]/y/g' <<<'x.\z' yyyz