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

Re: PATCH: =~ regex match



On 2007-04-26 at 13:19 -0700, Phil Pennock wrote:
> As to BASH_REMATCH ... how frowned upon are new zsh options which
> auto-set for compatibility?  It wouldn't be hard, since the
> infrastructure's all already in place.  Call the zsh option BASH_REMATCH
> to set the BASH_REMATCH variable.  :^)

I just double-checked something in passing and discovered that Bash uses
the equivalent of KSH_ARRAYS, so the variable would need to be marked
similarly to that and provided with the entire matched portion of the
string in index 0.

Would it be sufficient to assume that if someone's truly after bash
compat, ksh_arrays will be set, so inside the test isset(BASHREMATCH)
also check isset(KSHARRAYS) and if and only if that is set too, then
prepend the entire matched portion to the array?

Normal:
  set $MATCH to matched portion,
      ${match[@]} to captured substrings
BASH_REMATCH:
  set $MATCH to matched portion,
      ${BASH_REMATCH} to captured substrings
  => not full compat
BASH_REMATCH && KSH_ARRAYS
  set $MATCH to matched portion,
      ${BASH_REMATCH[0]} to matched portion too,
      ${BASH_REMATCH[1...n]} to captured substrings
  => full compat

Which highlights that =~ should also be setting $MATCH, not just $match.

Would it be okay to extend the -pcre-match operator to do the same?

What about the pcre_match builtin function -- should that also be
setting $MATCH and accept a "-v var" option to set a different variable,
similarly to "-a arr"?  If so, any preferences as to what the option
should be?

I'm willing to do this work, provided people think that it would be
fairly likely to be accepted.

Regards,
-Phil



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