zsh-users
 help / color / mirror / code / Atom feed
* Substitution question
@ 2004-07-20  1:14 Björn Lindström
  2004-07-20  7:15 ` DervishD
  0 siblings, 1 reply; 2+ messages in thread
From: Björn Lindström @ 2004-07-20  1:14 UTC (permalink / raw)
  To: zsh-users

Can somebody tell me what type of patterns are supported in l, in the
$x:s/l/r syntax?

I'd like to do something like:

$x:gs/[^A-Za-z0-9]/_

to replace all characters except for the ones listed with underscore.


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Substitution question
  2004-07-20  1:14 Substitution question Björn Lindström
@ 2004-07-20  7:15 ` DervishD
  0 siblings, 0 replies; 2+ messages in thread
From: DervishD @ 2004-07-20  7:15 UTC (permalink / raw)
  To: zsh-users

    Hi Björn :)

 * Björn Lindström <bkhl@elektrubadur.se> 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/


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-07-20  7:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-07-20  1:14 Substitution question Björn Lindström
2004-07-20  7:15 ` DervishD

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).