7 ms·
Isn't simpler to use perl? Perl -pe 's/.(capture this)./$1/' That way, you can capture multiple groups, and change the format in the output. You can also do s
by tatref 4y ago
Isn't simpler to use perl?
Perl -pe 's/.(capture this)./$1/'
That way, you can capture multiple groups, and change the format in the output. You can also do simple calculations if you capture numbers
- tryauuum 4y agofor me no, anything perl-related is not simple I also tried putting this question in GPT3: > Isn't simpler to use perl? > It is simpler to use Perl, but it is not as efficient as using C or C++.
- jraph 4y agoNice one, I'll try to counter this garbage GPT3 answer: - I don't think the regex engine in Perl is implemented in Perl. It's probably implemented in C/C++, like grep. libpcre is in C anyway. - Even if grep is/were more efficient, You might have consumed more time and energy thinking, typing and running "grep --only-matching --perl-regexp 'prefix \K\d+(?= suffix)'" than the suggested perl solution - I might have consumed even more energy typing this reply. My computer is there, waiting for me typing, doing not much.
- tryauuum 4y agoshorter version of the grep command is grep -oP 'prefix \K\d+(?= suffix)' but yeah, I know it's easier to me because I did read man page at some point (while carefully avoiding perl manuals) actually even that is not true, perldoc on regular expressions really helps even grep users
- jraph 4y agoIn all honesty, I'm more likely to remember this form than the Perl one, and once it's in the shell history, any will do anyway :-)
- melagonster 4y agogrep have perl regex mode.