Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: backreferences
On Oct 15, 11:28am, Ray Andrews wrote:
} Subject: backreferences
}
} sstring="before inside after"
} if [[ "$sstring" = (#b)([^i]#inside)(*) ]];
}
} ... all good. But is is possible to populate 'match'
} without the 'if' test?
The [[ ]] syntax is not part of the "if" syntax; "if" is followed by
a command whose exit status is tested, so [[ ]] is a command. Thus
you can simply write
[[ "$sstring" = (#b)([^i]#inside)(*) ]]
by itself. You do need the [[ ]] context to invoke pattern matching.
} Better question:
}
} In this construction " [^i] " is it possible to use a
} string rather than a character in the exclusion test?
I'm not sure what you're asking. In a pattern, [string] is a character
class (match any of s,t,r,i,n,g) and [^string] is the inverse of that
character class, but that whole subexpression always matches only one
character in the tested string.
So "use a string rather than a character" might mean that you want to
construct a character class by writing something similar to [^$class]
where the parameter $class needs to be expanded, or it might mean that
you're trying to not-match multiple characters in the tested string in
a certain order. In the latter case you want ^(string), or more often
(^(string)), but you also must setopt EXTENDED_GLOB.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author