@kabel42 @amin @sotolf @thedoctor @mirabilos
Interesting! I wonder what kind of algorithmic optimizations (as opposed to compiler optimizations) they're using to do that, and if regular (GNU/BSD) grep could do the same.
Because I'll wear clown shoes and a tutu before changing to a "rewrite the world in rust!" utility š
@kabel42 @rl_dane @amin @sotolf @thedoctor eww, itās not even a drop-in thenā¦
(For not-a-drop-in, I found pcregrep interesting. Sadly, Debian recently dropped it, but in the versions which donāt have pcregrep any more, you can use grep -P for many use cases. pcre2grep is not a drop-in for pcregrep eitherā¦)
@mirabilos @kabel42 @amin @sotolf @thedoctor
I was a total PCRE stan in the olden days, but I've steered more towards regular extended regexp for compatibility. I do miss \d, \w and \s, though. [[:space:]] feels so clumsy to type and use several times in a regex, I'll sometimes put a sp="[[:space:]]" line at the start of a script, and you'll see several invocations of "${sp}" in my regex strings.
But again... compatibility. ;)
Is there a big difference between (GNU) grep -P and pcregrep? I hadn't heard of that utility before.
@amin @kabel42 @rl_dane @sotolf @thedoctor I never used \d and the likes, always felt them much too complicated. I almost never use POSIX character classes (besides the BSD [[:<:]] and [[:>:]]), rather I just hit [ tab space ] quickly.
GNU grep -P does a PCRE grep, it doesnāt support all of the extra flags of pcregrep though, and before the version in IIRC trixie was very broken.
@mirabilos @amin @kabel42 @sotolf @thedoctor
is [[:<:]] and [[:>:]] the same as \< and \>?
@rl_dane @amin @kabel42 @sotolf @thedoctor obviously not, because itās written differently ;)
re_format(7) knows:
There are two special cases** of bracket expressions: the bracket expres-
sions '[[:<:]]' and '[[:>:]]' match the null string at the beginning and
end of a word, respectively. A word is defined as a sequence of charac-
ters starting and ending with a word character which is neither preceded
nor followed by word characters. A word character is an alnum character
(as defined by ctype(3)) or an underscore. This is an extension, compati-
ble with but not specified by POSIX, and should be used with caution in
software intended to be portable to other systems.
(as for the mark:)
POSIX leaves some aspects of RE syntax and semantics open; '**' marks de-
cisions on these aspects that may not be fully portable to other POSIX
implementations.
The definition for \< / \> differs between less, perlre, pcre, ⦠I believe, but they all are somewhat simiar.
@rl_dane @amin @kabel42 @sotolf @thedoctor perlre(1) actually hasā¦
A word boundary ("\b") is a spot between two characters that
has a "\w" on one side of it and a "\W" on the other side of
it (in either order), counting the imaginary characters off
the beginning and end of the string as matching a "\W".
⦠so the \< probably comes from less(1)?
⦠hm, no. But, where then?
@mirabilos @amin @kabel42 @sotolf @thedoctor
I used to use \b a lot, but \< and \> are just as easy to use, and POSIX. ;)
\w is nice, though. I think the closest POSIX one is [[:graph:]]? (Not super close, though)
@rl_dane @amin @kabel42 @sotolf @thedoctor \< and \> are not POSIX.
perlre(1) \w is identical to POSIX [a-zA-Z0-9_] in the C locale, so [[:alnum:]_] if you have support for POSIX character classes.
@mirabilos @amin @kabel42 @sotolf @thedoctor
Ah, yes. [[:alnum:]] was the one I was thinking of.
@mirabilos @amin @kabel42 @sotolf @thedoctor
Waiiiiit, what does the underscore before the second bracket do? I've never seen that before.
No mention of it in RE_FORMAT(7) on FreeBSD.
[a-zA-Z0-9_], and Iād be surprised if the FreeBSD manpage would not document it@rl_dane @amin @kabel42 @sotolf @thedoctor let me blow your mind if that was news to you:
[[:alpha:][:digit:]_]
[ switches from RE context to RE-Bracket context in the bracket-begin state, in which you can have an optional ^ (except in shellglobs where it is spelt !), then an optional ] not taken as the end of the RE-Bracket, then an optional -, then any amount of expressions of the type a-z, [:charclass:], [=equivalenceclass=], x, then an optional -, then a closing ] which terminates the RE-Bracket context.] or the - at the beginning, not both)[a[.ch.]] in e.g. es_ES.UTF-8 matches either a or ch, so a bracket expression in POSIX has a variable matching lengthā¦)[[:<:]] and [[:>:]] extension (which matches a zero-length string)@kabel42 @mirabilos @amin @sotolf @thedoctor
Basically spaces and punctuation.
[^char-class] matches āany single character, other than newline, not in char-classā@kabel42 @rl_dane @amin @sotolf @thedoctor yea, Iām just pedantic.
In the RE ^foo[^bar^]baz$ there technically are exactly two carets.
] or - in a bracket expression, and for the newline ofc.@mirabilos @kabel42 @amin @sotolf @thedoctor
Don't you have to backslash escape a right bracket, like [a-z\]]?
[]a-z]@mirabilos @sotolf @thedoctor @amin @kabel42
Ahhhh, good to know. Mentally filed. ;)
@kabel42 @amin @thedoctor @sotolf @rl_dane I often go through logs by first cutting off timestamp
and host using rectangle mode in jupp, then replacing ^([^ ]*)\[[^]]*\]: with \1: and sort -uing.
Iāve also used [][0-9a-fA-F:] to match IP addressesā¦
@mirabilos @kabel42 @amin @thedoctor @sotolf
I love editors with rectangle selection and editing modes. vim has it, and my first exposure to it was actually in Microsoft Word 4.0 for mac. Obviously not something I use today. XD
@kabel42 @mirabilos @amin @thedoctor @sotolf
Looking online... is it ctrl+shift+B?