OT: grep

Miroslav Prýmek m.prymek at gmail.com
Sun Jul 29 09:42:09 CEST 2012


2012/7/27 Jan Pechanec <jp na devnull.cz>:
>>Ja bych nerekl "takhle se chova i shell" ale "takhle se chova shell" a
>>dodal, ze to neznamena, ze se tak bude chovat kazdej program.
>
>         ok, tak to preformuluju tak, ze jsem tohle chovani nikdy nikde
> nezaregistroval, pouze to opacny. Co si vzpominam, tak perlovsky regularni
> vyrazy take umoznuji "\a" a je to jako "a".
>

Jenom tak pro zajimavost, se takhle chovaji oba dva moje oblibene
jazyky (a oba konzistentne):

Python:

The special sequences consist of '\' and a character from the list
below. If the ordinary character is not on the list, then the
resulting RE will match the second character.

>>> re.match('\`','`')
<_sre.SRE_Match object at 0x100485098>
>>> re.match('\X','X')
<_sre.SRE_Match object at 0x100485100>

I Erlang:

u vsech string literalu:
> io:format("~w~n",["\`"]).
[96]

...a i u RE:
This escaping action applies whether or not the following character
would otherwise be interpreted as a metacharacter, so it is always
safe to precede a non-alphanumeric with backslash to specify that it
stands for itself. In particular, if you want to match a backslash,
you write \\.

> re:run("`","\\`").
{match,[{0,1}]}
> re:run("X","\\X").
{match,[{0,1}]}

...jenom tak pro ilustraci :)

M.


More information about the Users-l mailing list