Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Substitution question

    Hi Björn :)

 * Björn Lindström <bkhl@xxxxxxxxxxxxxxx> dixit:
> Can somebody tell me what type of patterns are supported in l, in the
> $x:s/l/r syntax?

    Read the info manual, section 'History Expansion', node
'Modifiers'. Scroll down a bit and you'll find the answer. The 'l'
part is not a regex :(
> I'd like to do something like:
> $x:gs/[^A-Za-z0-9]/_
> to replace all characters except for the ones listed with underscore.

    ¿How about using ${x//PATTERN/REPLACEMENT}? Then you can use the
patterns valid for filename generation (sort of a regex, more or less
powerful depending on the option 'EXTENDED_GLOB'. For your example, I
would do:

    print ${x//[^[:alnum:]]/_}

    Whether to use 'print' or not is up to your particular use. The
double '//' is to say 'make substitutions global, not only the
first', and the 'regex' is to say 'al non alphanumeric characters'.
Hope this helps.

    Raúl Núñez de Arenas Coronado

Linux Registered User 88736
http://www.pleyades.net & http://raul.pleyades.net/

Messages sorted by: Reverse Date, Date, Thread, Author