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

Re: regexing to remove punctutation in telephone numbers



Eric Smith wrote:
> 
> > 
> > myfax () {
> >         command myfax "${1//[-()]}${2//[-()]}" ${argv[3,-1]}
> > }
> 
> There can be n number of args with the offending punctutation characters.  
> And n should be determined from the first arg that commences in a non
> [-()0-9] character.

myfax() {
  local last=${argv[(i)[^-()0-9]*]}
 
  command myfax "${(j..)argv[1,last-1]//[-()]}" "$argv[last,-1]"   
}

That uses the (i) subscript flag to find the first arg commencing with
a different character. I'd be inclined to check all characters:
  (^[-()0-9]#)
You could use a loop to do the same.



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