2 ms·
I don't see it. The regex is mostly hard to read because they formatted it poorly and put in a bunch of unnecessary non-capturing groups. I find this to be just
by pavon 6y ago
I don't see it. The regex is mostly hard to read because they formatted it poorly and put in a bunch of unnecessary non-capturing groups. I find this to be just as easy (if not easier) to read as their first example:
String pattern = (
"(\d+)\t"+
"(\d+)\t"+
"([0-1])\t"+
"(http://localhost:20\d{3})\t"+
"([0-1])\t"+
"(\d+)\t"+
"([0-1])\t"+
"(\d+)\t"+
"(\d+)\t"+
"([0-1])\t"+
"(\d+)\t"+
"(STR[0-2])"
);
And this is just as easy to read as their second example:
String num = "(\d+)\t";
String bool = "([0-1])\t";
String url = "(http://localhost:20\d{3})\t";
String str = "(STR[0-2])";
String pattern = num+num+bool+url+bool+num+bool+num+num+bool+num+str;
And yes, I do frequently split up my regexes like that to make them more readable.
The only improvement I see is that you don't have messy escaping in the url. That is genuinely nice. It motivates me to start using an regEsc() function instead of doing it by hand. However, I find "capt().endCapture()", and other verboseness to be a step backwards.
Edit: Actually, from what I can tell, all the escaping was unnecessary in this case as well. Updated examples without unneeded escape characters.