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

Re: matching flags (was: Re: Should we backup this change? RE: Modifier substitutions.)



Sven Wischnowsky wrote:
>Before I forget it... from the code in pattern.c it doesn't look too
>hard to support flags for the other special `gaps between characters'
>supported by some regexp systems (beginning/end of line/word). Would
>it be interesting enough to have them, too? Might be useful with
>parsing command outputs as in ${$(...)...} sometimes. (The definition
>of `word' might be a problem, of course...)

The more general solution would be to support user-specified anchors.
Word/line anchors can be defined in terms of lookahead/lookback assertions
(like Perl's (?!)).  Suppose we define anchors thus:

	(#A			indicates anchor
	   a			indicates looking ahead
	   b			indicates looking back
	    n			(optional) negates the anchor result
	     :			separates flags from pattern
	      <pattern>)	pattern to check for

Then a `beginning of line' anchor (matching at the start of the string
or after an embedded newline) could be implemented as

	(#Ab:(#s)|$'\n')

(in this case, the (#s) could be taken out of the anchor).  One reasonable
`beginning of word' anchor would be

	(#Abn:[a-zA-Z0-9_])(#Aa:[a-zA-Z0-9_])

(read as "there is a word character immediately ahead, but not one
immediately behind").  Of course, anyone that uses these anchors
frequently would put them into a parameter, so that they can be invoked
as $~bol, etc.

-zefram



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