%%
%% This is file `regexpatch.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% regexpatch.dtx  (with options: `package')
%% 
%% Do not distribute this file without also distributing the
%% source files specified above.
%% 
 % \iffalse meta-comment
%% File: regexpatch.dtx (C) Copyright 2012-2016 Enrico Gregorio
%%
%% It may be distributed and/or modified under the conditions of the
%% LaTeX Project Public License (LPPL), either version 1.3c of this
%% license or (at your option) any later version.  The latest version
%% of this license is in the file
%%
%%    http://www.latex-project.org/lppl.txt
%%
%% This file is part of the "regexpatch bundle" (The Work in LPPL)
%% and all files in that bundle must be distributed together.
%%
%% The released version of this bundle is available from CTAN.
%%
\RequirePackage{expl3}
\GetIdInfo$Id: regexpatch.dtx 0.2d 2018-05-02 12:00:00Z Enrico $
          {Extending etoolbox patching commands}
\ProvidesExplPackage
  {\ExplFileName}{\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription}
\@ifpackagelater { expl3 } { 2012/01/19 }
  { }
  {
    \PackageError { regexpatch } { Support~package~l3kernel~too~old. }
      {
        Please~install~an~up~to~date~version~of~l3kernel~
        using~your~TeX~package~manager~or~from~CTAN.\\ \\
        Loading~regexpatch~will~abort!
      }
    \tex_endinput:D
  }
\RequirePackage{xparse}
\bool_new:N \l_xpatch_protect_bool
\bool_new:N \l_xpatch_optional_bool
\bool_new:N \l_xpatch_patchable_bool
\bool_new:N \l_xpatch_tracing_bool
\tl_new:N \l_xpatch_name_tl
\tl_new:N \l_xpatch_repl_tl
\tl_new:N \l_xpatch_prefix_tl
\tl_new:N \l_xpatch_arg_tl
\tl_new:N \l_xpatch_replacement_tl
\tl_new:N \l_xpatch_type_tl % for debugging messages
\cs_generate_variant:Nn \regex_match:nnT {nV}
\cs_new_protected:Npn \xpatch_main_check:N #1
  {
   \bool_set_false:N \l_xpatch_protect_bool
   \bool_set_false:N \l_xpatch_optional_bool
   \tl_set:Nx \l_xpatch_name_tl { \cs_to_str:N #1  }
   \tl_set:Nx \l_xpatch_repl_tl { \token_get_replacement_spec:N #1 }
   \tl_clear:N \l_xpatch_type_tl
   \regex_match:nVT % \DeclareRobustCommand<control word>
     {^\\protect\ \\\u{l_xpatch_name_tl}\ \ }
     \l_xpatch_repl_tl
     {
      \bool_set_true:N \l_xpatch_protect_bool
      \tl_put_right:Nx \l_xpatch_name_tl { \c_space_tl }
      \tl_set:Nn \l_xpatch_type_tl { DRCw }
     }
   \regex_match:nVT % \DeclareRobustCommand<control symbol>
     {^\\x@protect\ \\\u{l_xpatch_name_tl}\\}
     \l_xpatch_repl_tl
     {
      \bool_set_true:N \l_xpatch_protect_bool
      \tl_put_right:Nx \l_xpatch_name_tl { \c_space_tl }
      \tl_set:Nn \l_xpatch_type_tl { DRCs }
     }
   \regex_match:nVT % \newcommand<control word> with opt arg
     {^\\@protected@testopt\ \\\u{l_xpatch_name_tl}\ \\\\}
     \l_xpatch_repl_tl
     {
      \bool_set_true:N \l_xpatch_optional_bool
      \tl_put_left:Nx \l_xpatch_name_tl { \c_backslash_str }
      \tl_set:Nn \l_xpatch_type_tl { ncw+o }
     }
   \regex_match:nVT % \newcommand<control symbol> with opt arg
     {^\\@protected@testopt\ \\\u{l_xpatch_name_tl}\\\\}
     \l_xpatch_repl_tl
     {
      \bool_set_true:N \l_xpatch_optional_bool
      \tl_put_left:Nx \l_xpatch_name_tl { \c_backslash_str }
      \tl_set:Nn \l_xpatch_type_tl { ncs+o }
     }
   \regex_match:nVT % \newrobustcmd<any cs> with opt arg
     {^\\@testopt\ \\\\\u{l_xpatch_name_tl}}
     \l_xpatch_repl_tl
     {
      \bool_set_true:N \l_xpatch_optional_bool
      \tl_put_left:Nx \l_xpatch_name_tl { \c_backslash_str }
      \tl_set:Nn \l_xpatch_type_tl { nrc+o }
     }
   \bool_if:NT \l_xpatch_protect_bool
     {
      \tl_set:Nx \l_xpatch_repl_tl
        { \exp_after:wN \token_get_replacement_spec:N
            \cs:w \l_xpatch_name_tl \cs_end: }
      \regex_match:nVT % \DeclareRobustCommand<any cs> with opt arg
        {^\\@protected@testopt\ \\\u{l_xpatch_name_tl}\ \\\\}
        \l_xpatch_repl_tl
        {
         \bool_set_true:N \l_xpatch_optional_bool
         \tl_put_left:Nx \l_xpatch_name_tl { \c_backslash_str }
         \tl_put_right:Nn \l_xpatch_type_tl { +o }
        }
     }
   \bool_if:NT \l_xpatch_optional_bool
     {
      \regex_replace_once:nnN { .*? \{ (.*) \} \Z } { \1 }
        \l_xpatch_repl_tl
     }
  }
\cs_new_protected:Npn \xpatch_main_four:NNnnnn #1 #2 #3 #4 #5 #6
  {
   \cs_if_exist:NTF #2
     {
      \xpatch_main_check:N #2
      \bool_if:NT \l_xpatch_tracing_bool
        { \xpatch_message_cstype:N #2 }
      \exp_after:wN #1 \cs:w \l_xpatch_name_tl \cs_end: {#3}{#4}{#5}{#6}
     }
     {
      \msg_term:n
        {
         xpatch~message \\
        `\token_to_str:N #2'~is~undefined;~
        I'll~ignore~the~request.
        }
     }
  }
\cs_new_protected:Npn \xpatch_main_three:NNnnn #1 #2 #3 #4 #5
 {
  \xpatch_main_four:NNnnnn #1 #2 { #3 } { #4 } { #5 } { }
 }
\cs_new_protected:Npn \xpatch_main_zero:NN #1 #2
 {
  \xpatch_main_four:NNnnnn #1 #2 { } { } { } { }
 }
\cs_generate_variant:Nn \xpatch_main_zero:NN {Nc}
\cs_generate_variant:Nn \xpatch_main_three:NNnnn {Nc}
\cs_generate_variant:Nn \xpatch_main_four:NNnnnn {Nc}
\cs_new_protected:Npn \xpatch_get_all:N #1
  {
   \tl_set:Nf \l_xpatch_prefix_tl { \token_get_prefix_spec:N #1 }
   \tl_set_rescan:Nnx \l_xpatch_prefix_tl { } \l_xpatch_prefix_tl
   \tl_set:Nf \l_xpatch_arg_tl { \token_get_arg_spec:N #1 }
   \tl_set_rescan:Nnx \l_xpatch_arg_tl { } \l_xpatch_arg_tl
   \tl_set:Nf \l_xpatch_replacement_tl { \token_get_replacement_spec:N #1 }
   \tl_set_rescan:Nnx \l_xpatch_replacement_tl { } \l_xpatch_replacement_tl
  }
\cs_new_protected:Npn \xpatch_rebuild:N #1
  {
   \use:x
     {
      \exp_not:V \l_xpatch_prefix_tl
      \tex_def:D % unavoidable
      \exp_not:N #1
      \exp_not:V \l_xpatch_arg_tl
      { \exp_not:V \l_xpatch_replacement_tl }
     }
  }
\cs_new_protected:Npn \xpatch_check_patchable:N #1
  {
   \cs_if_exist:NTF #1
     {
      \xpatch_get_all:N #1
      \xpatch_rebuild:N \xpatch_tmpa:w
      \cs_if_eq:NNTF #1 \xpatch_tmpa:w
        {
         \bool_set_true:N \l_xpatch_patchable_bool
         \xpatch_message:n
           {
            Macro `\token_to_str:N #1'~is~patchable
           }
        }
        {
         \bool_set_false:N \l_xpatch_patchable_bool
         \xpatch_message:n
           {
            Macro `\token_to_str:N #1'~is~NOT~patchable\\
            (Check~if~it~contains~`@'~commands)
           }
        }
     }
     {
      \bool_set_false:N \l_xpatch_patchable_bool
      \xpatch_message:n
        {
         Macro `\token_to_str:N #1'~doesn't~exist.
        }
     }
  }
\cs_new_protected:Npn \xpatch_pretocmd:Nnnn #1 #2 #3 #4
  {
   \xpatch_check_patchable:N #1
   \bool_if:NTF \l_xpatch_patchable_bool
      {
       \tl_put_left:Nn \l_xpatch_replacement_tl { #2 }
       \xpatch_rebuild:N #1
       #3
      }
      {
       #4
      }
  }
\cs_new_protected:Npn \xpatch_apptocmd:Nnnn #1 #2 #3 #4
  {
   \xpatch_check_patchable:N #1
   \bool_if:NTF \l_xpatch_patchable_bool
      {
       \tl_put_right:Nn \l_xpatch_replacement_tl { #2 }
       \xpatch_rebuild:N #1
       #3
      }
      {
       #4
      }
  }
\cs_new_protected:Npn \xpatch_regexpatchcmd_all:Nnnnn #1 #2 #3 #4 #5
  {
   \xpatch_check_patchable:N #1
   \bool_if:NTF \l_xpatch_patchable_bool
      {
       \regex_replace_all:nnNTF { #2 } { #3 } \l_xpatch_replacement_tl
        { \xpatch_rebuild:N #1 #4 }
        { #5 }
      }
      {
       #5
      }
  }
\cs_new_protected:Npn \xpatch_regexpatchcmd_once:Nnnnn #1 #2 #3 #4 #5
  {
   \xpatch_check_patchable:N #1
   \bool_if:NTF \l_xpatch_patchable_bool
      {
       \regex_replace_once:nnNTF { #2 } { #3 } \l_xpatch_replacement_tl
        { \xpatch_rebuild:N #1 #4 }
        { #5 }
      }
      {
       #5
      }
  }
\cs_new_protected:Npn \xpatch_patchcmd_once:Nnnnn #1 #2 #3 #4 #5
  {
   \xpatch_check_patchable:N #1
   \bool_if:NTF \l_xpatch_patchable_bool
      {
       \tl_set:Nn \l_tmpa_tl { #2 }
       \tl_set:Nn \l_tmpb_tl { #3 }
       \regex_replace_once:nnNTF
         { \u{l_tmpa_tl} }
         { \u{l_tmpb_tl} }
         \l_xpatch_replacement_tl
         { \xpatch_rebuild:N #1 #4 }
         { #5 }
      }
      {
       #5
      }
  }
\cs_new_protected:Npn \xpatch_patchcmd_all:Nnnnn #1 #2 #3 #4 #5
  {
   \xpatch_check_patchable:N #1
   \bool_if:NTF \l_xpatch_patchable_bool
      {
       \tl_set:Nn \l_tmpa_tl { #2 }
       \tl_set:Nn \l_tmpb_tl { #3 }
       \regex_replace_all:nnNTF
         { \u{l_tmpa_tl} }
         { \u{l_tmpb_tl} }
         \l_xpatch_replacement_tl
         { \xpatch_rebuild:N #1 #4 }
         { #5 }
      }
      {
       #5
      }
  }
\cs_new_protected:Npn \xpatch_message:n #1
  {
   \bool_if:NT \l_xpatch_tracing_bool
     {
      \msg_term:n { xpatch~message \\ #1 }
     }
  }
\cs_new:Npn \xpatch_message_cstype:N #1
  {
   \str_case:onF { \l_xpatch_type_tl }
     {
      { DRCw }   {
                  \xpatch_message:n
                    {
                     `\token_to_str:N #1'~is~a~control~word~defined~
                     with~\token_to_str:N \DeclareRobustCommand
                    }
                 }
      { DRCw+o } {
                  \xpatch_message:n
                    {
                     `\token_to_str:N #1'~is~a~control~word~defined~
                     with~`\token_to_str:N \DeclareRobustCommand'~
                     and~a~default~optional~argument~`\l_xpatch_repl_tl'
                    }
                 }
      { DRCs }   {
                  \xpatch_message:n
                    {
                     `\token_to_str:N #1'~is~a~control~symbol~defined~
                     with~`\token_to_str:N \DeclareRobustCommand'
                    }
                 }
      { DRCs+o } {
                  \xpatch_message:n
                    {
                     `\token_to_str:N #1'~is~a~control~symbol~defined~
                     with~`\token_to_str:N \DeclareRobustCommand'~
                     and~a~default~optional~argument~`\l_xpatch_repl_tl'
                    }
                 }
      { ncw+o }  {
                  \xpatch_message:n
                    {
                     `\token_to_str:N #1'~is~a~control~word~defined~
                     with~`\token_to_str:N \newcommand'~
                     and~a~default~optional~argument~`\l_xpatch_repl_tl'
                    }
                 }
      { ncs+o }  {
                  \xpatch_message:n
                    {
                     `\token_to_str:N #1'~is~a~control~symbol~defined~
                     with~`\token_to_str:N \newcommand'~
                     and~a~default~optional~argument~`\l_xpatch_repl_tl'
                    }
                 }
      { nrc+o }  {
                  \xpatch_message:n
                    {
                     `\token_to_str:N #1'~is~a~control~sequence~defined~
                     with~`\token_to_str:N \newrobustcmd'~
                     and~a~default~optional~argument~`\l_xpatch_repl_tl'
                    }
                 }
      }
      {
       \xpatch_message:n
         {
          `\token_to_str:N #1'~is~not~especially~defined
         }
      }
  }
\NewDocumentCommand{\xshowcmd} { s +m }
 {
  \IfBooleanT{#1}
   {
    \group_begin:
    \bool_set_true:N \l_xpatch_tracing_bool
   }
  \xpatch_main_zero:NN \cs_show:N #2
  \IfBooleanT{#1}
   {
    \group_end:
   }
 }
\NewDocumentCommand{\xpretocmd}{ +m +m +m +m }
 { \xpatch_main_three:NNnnn \xpatch_pretocmd:Nnnn #1 {#2} {#3} {#4} }
\NewDocumentCommand{\xapptocmd}{ +m +m +m +m }
 { \xpatch_main_three:NNnnn \xpatch_apptocmd:Nnnn #1 {#2} {#3} {#4} }
\NewDocumentCommand{\regexpatchcmd}{ s +m +m +m +m +m }
 {
  \IfBooleanTF{#1}
   { \xpatch_main_four:NNnnnn \xpatch_regexpatchcmd_all:Nnnnn #2 {#3}{#4}{#5}{#6} }
   { \xpatch_main_four:NNnnnn \xpatch_regexpatchcmd_once:Nnnnn #2 {#3}{#4}{#5}{#6} }
 }
\NewDocumentCommand{\xpatchcmd}{ s +m +m +m +m +m }
 {
  \IfBooleanTF{#1}
   { \xpatch_main_four:NNnnnn \xpatch_patchcmd_all:Nnnnn #2 {#3}{#4}{#5}{#6} }
   { \xpatch_main_four:NNnnnn \xpatch_patchcmd_once:Nnnnn #2 {#3}{#4}{#5}{#6} }
 }
\NewDocumentCommand{\xshowbibmacro} { s +m }
 {
  \IfBooleanT{#1}
   {
    \group_begin:
    \bool_set_true:N \l_xpatch_tracing_bool
   }
  \xpatch_main_zero:Nc \cs_show:N { abx@macro@ \tl_to_str:n {#2} }
  \IfBooleanT{#1}
   {
    \group_end:
   }
 }
\NewDocumentCommand{\xpretobibmacro} { +m +m +m +m }
 {
  \xpatch_main_three:Ncnnn \xpatch_pretocmd:Nnnn
   { abx@macro@ \tl_to_str:n {#1} } {#2}{#3}{#4}
 }
\NewDocumentCommand{\xapptobibmacro} { +m +m +m +m }
 {
  \xpatch_main_three:Ncnnn \xpatch_apptocmd:Nnnn
   { abx@macro@ \tl_to_str:n {#1} } {#2}{#3}{#4}
 }
\NewDocumentCommand{\xpatchbibmacro} { s +m +m +m +m +m }
 {
  \IfBooleanTF{#1}
   {
    \xpatch_main_four:Ncnnnn \xpatch_patchcmd_all:Nnnnn
     { abx@macro@ \tl_to_str:n {#2} } {#3}{#4}{#5}{#6}
   }
   {
    \xpatch_main_four:Ncnnnn \xpatch_patchcmd_once:Nnnnn
     { abx@macro@ \tl_to_str:n {#2} } {#3}{#4}{#5}{#6}
   }
 }
\NewDocumentCommand{\regexpatchbibmacro} { s +m +m +m +m +m }
 {
  \IfBooleanTF{#1}
   {
    \xpatch_main_four:Ncnnnn \xpatch_regexpatchcmd_all:Nnnnn
     { abx@macro@ \tl_to_str:n {#2} } {#3}{#4}{#5}{#6}
   }
   {
    \xpatch_main_four:Ncnnnn \xpatch_regexpatchcmd_once:Nnnnn
     { abx@macro@ \tl_to_str:n {#2} } {#3}{#4}{#5}{#6}
   }
 }
\NewDocumentCommand{\xshowbibdriver} { s +m }
 {
  \IfBooleanT{#1}
   {
    \group_begin:
    \bool_set_true:N \l_xpatch_tracing_bool
   }
  \xpatch_main_zero:Nc \cs_show:N { blx@bbx@#2 }
  \IfBooleanT{#1}
   {
    \group_end:
   }
 }
\NewDocumentCommand{\xpretobibdriver} { +m +m +m +m }
 { \exp_args:Nc \xpatch_pretocmd:Nnnn {blx@bbx@#1} {#2}{#3}{#4} }
\NewDocumentCommand{\xapptobibdriver} { +m +m +m +m }
 { \exp_args:Nc \xpatch_apptocmd:Nnnn {blx@bbx@#1} {#2}{#3}{#4} }
\NewDocumentCommand{\xpatchbibdriver} { s +m +m +m +m +m }
 {
  \IfBooleanTF{#1}
   { \exp_args:Nc \xpatch_patchcmd_all:Nnnnn {blx@bbx@#2} {#3}{#4}{#5}{#6} }
   { \exp_args:Nc \xpatch_patchcmd_once:Nnnnn {blx@bbx@#2} {#3}{#4}{#5}{#6} }
 }
\NewDocumentCommand{\regexpatchbibdriver} { s +m +m +m +m +m }
 {
  \IfBooleanTF{#1}
   { \exp_args:Nc \xpatch_regexpatchcmd_all:Nnnnn {blx@bbx@#2} {#3}{#4}{#5}{#6} }
   { \exp_args:Nc \xpatch_regexpatchcmd_once:Nnnnn {blx@bbx@#2} {#3}{#4}{#5}{#6} }
 }
\NewDocumentCommand{\xshowfieldformat} { s O{*} +m }
 {
  \IfBooleanT{#1}
   {
    \group_begin:
    \bool_set_true:N \l_xpatch_tracing_bool
   }
  \xpatch_main_zero:Nc \cs_show:N { abx@ffd@ \tl_to_str:n {#2} @ \tl_to_str:n {#3} }
  \IfBooleanT{#1}
   {
    \group_end:
   }
 }
\NewDocumentCommand{\xpretofieldformat} { s O{*} +m +m +m +m }
 {
  \IfBooleanTF{#1}
   {
    \xpatch_main_three:Ncnnn \xpatch_pretocmd_all:Nnnn
     { abx@ffd@ \tl_to_str:n {#2} @ \tl_to_str:n {#3} } {#4}{#5}{#6}
   }
   {
    \xpatch_main_three:Ncnnn \xpatch_pretocmd_once:Nnnn
     { abx@ffd@ \tl_to_str:n {#2} @ \tl_to_str:n {#3} } {#4}{#5}{#6}
   }
 }
\NewDocumentCommand{\xapptofieldformat} { s O{*} +m +m +m +m }
 {
  \IfBooleanTF{#1}
   {
    \xpatch_main_three:Ncnnn \xpatch_apptocmd_all:Nnnn
     { abx@ffd@ \tl_to_str:n {#2} @ \tl_to_str:n {#3} } {#4}{#5}{#6}
   }
   {
    \xpatch_main_three:Ncnnn \xpatch_apptocmd_once:Nnnn
     { abx@ffd@ \tl_to_str:n {#2} @ \tl_to_str:n {#3} } {#4}{#5}{#6}
   }
 }
\NewDocumentCommand{\xpatchfieldformat} { s O{*} +m +m +m +m +m }
 {
  \IfBooleanTF{#1}
   {
    \xpatch_main_four:Ncnnnn \xpatch_patchcmd_all:Nnnnn
     { abx@ffd@ \tl_to_str:n {#2} @ \tl_to_str:n {#3} } {#4}{#5}{#6}{#7}
   }
   {
    \xpatch_main_four:Ncnnnn \xpatch_patchcmd_once:Nnnnn
     { abx@ffd@ \tl_to_str:n {#2} @ \tl_to_str:n {#3} } {#4}{#5}{#6}{#7}
   }
 }
\NewDocumentCommand{\regexpatchfieldformat} { s O{*} +m +m +m +m +m }
 {
  \IfBooleanTF{#1}
   {
    \xpatch_main_four:Ncnnnn \xpatch_regexpatchcmd_all:Nnnnn
     { abx@ffd@ \tl_to_str:n {#2} @ \tl_to_str:n {#3} } {#4}{#5}{#6}{#7}
   }
   {
    \xpatch_main_four:Ncnnnn \xpatch_regexpatchcmd_once:Nnnnn
     { abx@ffd@ \tl_to_str:n {#2} @ \tl_to_str:n {#3} } {#4}{#5}{#6}{#7}
   }
 }

\NewDocumentCommand{\xshownameformat} { s O{*} +m }
 {
  \IfBooleanT{#1}
   {
    \group_begin:
    \bool_set_true:N \l_xpatch_tracing_bool
   }
  \xpatch_main_zero:Nc \cs_show:N { abx@nfd@ \tl_to_str:n {#1} @ \tl_to_str:n {#2} }
  \IfBooleanT{#1}
   {
    \group_end:
   }
 }
\NewDocumentCommand{\xpretonameformat} { s O{*} +m +m +m +m }
 {
  \IfBooleanTF{#1}
   {
    \xpatch_main_three:Ncnnn \xpatch_pretocmd_all:Nnnn
     { abx@nfd@ \tl_to_str:n {#2} @ \tl_to_str:n {#3} } {#4}{#5}{#6}
   }
   {
    \xpatch_main_three:Ncnnn \xpatch_pretocmd_once:Nnnn
     { abx@nfd@ \tl_to_str:n {#2} @ \tl_to_str:n {#3} } {#4}{#5}{#6}
   }
 }
\NewDocumentCommand{\xapptonameformat} { s O{*} +m +m +m +m }
 {
  \IfBooleanTF{#1}
   {
   \xpatch_main_three:Ncnnn \xpatch_apptocmd_all:Nnnn
     { abx@nfd@ \tl_to_str:n {#2} @ \tl_to_str:n {#3} } {#4}{#5}{#6}
   }
   {
    \xpatch_main_three:Ncnnn \xpatch_apptocmd_once:Nnnn
     { abx@nfd@ \tl_to_str:n {#2} @ \tl_to_str:n {#3} } {#4}{#5}{#6}
   }
 }
\NewDocumentCommand{\xpatchnameformat} { s O{*} +m +m +m +m +m }
 {
  \IfBooleanTF{#1}
   {
    \xpatch_main_four:Ncnnnn \xpatch_patchcmd_all:Nnnnn
     { abx@nfd@ \tl_to_str:n {#2} @ \tl_to_str:n {#3} } {#4}{#5}{#6}{#7}
   }
   {
    \xpatch_main_four:Ncnnnn \xpatch_patchcmd_once:Nnnnn
     { abx@nfd@ \tl_to_str:n {#2} @ \tl_to_str:n {#3} } {#4}{#5}{#6}{#7}
   }
 }
\NewDocumentCommand{\regexpatchnameformat} { s O{*} +m +m +m +m +m }
 {
  \IfBooleanTF{#1}
   {
    \xpatch_main_four:Ncnnnn \xpatch_regexpatchcmd_all:Nnnnn
     { abx@nfd@ \tl_to_str:n {#2} @ \tl_to_str:n {#3} } {#4}{#5}{#6}{#7}
   }
   {
    \xpatch_main_four:Ncnnnn \xpatch_regexpatchcmd_once:Nnnnn
     { abx@nfd@ \tl_to_str:n {#2} @ \tl_to_str:n {#3} } {#4}{#5}{#6}{#7}
   }
 }

\NewDocumentCommand{\xshowlistformat} { s O{*} +m }
 {
  \IfBooleanT{#1}
   {
    \group_begin:
    \bool_set_true:N \l_xpatch_tracing_bool
   }
  \xpatch_main_zero:Nc \cs_show:N { abx@lfd@ \tl_to_str:n {#1} @ \tl_to_str:n {#2} }
  \IfBooleanT{#1}
   {
    \group_end:
   }
 }
\NewDocumentCommand{\xpretolistformat} { s O{*} +m +m +m +m }
 {
  \IfBooleanTF{#1}
   {
    \xpatch_main_three:Ncnnn \xpatch_pretocmd_all:Nnnn
     { abx@lfd@ \tl_to_str:n {#2} @ \tl_to_str:n {#3} } {#4}{#5}{#6}
   }
   {
    \xpatch_main_three:Ncnnn \xpatch_pretocmd_once:Nnnn
     { abx@lfd@ \tl_to_str:n {#2} @ \tl_to_str:n {#3} } {#4}{#5}{#6}
   }
 }
\NewDocumentCommand{\xapptolistformat} { s O{*} +m +m +m +m }
 {
  \IfBooleanTF{#1}
   {
    \xpatch_main_three:Ncnnn \xpatch_apptocmd_all:Nnnn
     { abx@lfd@ \tl_to_str:n {#2} @ \tl_to_str:n {#3} } {#4}{#5}{#6}
   }
   {
    \xpatch_main_three:Ncnnn \xpatch_apptocmd_once:Nnnn
     { abx@lfd@ \tl_to_str:n {#2} @ \tl_to_str:n {#3} } {#4}{#5}{#6}
   }
 }
\NewDocumentCommand{\xpatchlistformat} { s O{*} +m +m +m +m +m }
 {
  \IfBooleanTF{#1}
   {
    \xpatch_main_four:Ncnnnn \xpatch_patchcmd_all:Nnnnn
     { abx@lfd@ \tl_to_str:n {#2} @ \tl_to_str:n {#3} } {#4}{#5}{#6}{#7}
   }
   {
    \xpatch_main_four:Ncnnnn \xpatch_patchcmd_once:Nnnnn
     { abx@lfd@ \tl_to_str:n {#2} @ \tl_to_str:n {#3} } {#4}{#5}{#6}{#7}
   }
 }
\NewDocumentCommand{\regexpatchlistformat} { s O{*} +m +m +m +m +m }
 {
  \IfBooleanTF{#1}
   {
    \xpatch_main_four:Ncnnnn \xpatch_regexpatchcmd_all:Nnnnn
     { abx@lfd@ \tl_to_str:n {#2} @ \tl_to_str:n {#3} } {#4}{#5}{#6}{#7}
   }
   {
    \xpatch_main_four:Ncnnnn \xpatch_regexpatchcmd_once:Nnnnn
     { abx@lfd@ \tl_to_str:n {#2} @ \tl_to_str:n {#3} } {#4}{#5}{#6}{#7}
   }
 }

\NewDocumentCommand{\xshowindexfieldformat} { s O{*} +m }
 {
  \IfBooleanT{#1}
   {
    \group_begin:
    \bool_set_true:N \l_xpatch_tracing_bool
   }
  \xpatch_main_zero:Nc \cs_show:N { abx@fid@ \tl_to_str:n {#1} @ \tl_to_str:n {#2} }
  \IfBooleanT{#1}
   {
    \group_end:
   }
 }
\NewDocumentCommand{\xpretoindexfieldformat} { s O{*} +m +m +m +m }
 {
  \IfBooleanTF{#1}
   {
    \xpatch_main_three:Ncnnn \xpatch_pretocmd_all:Nnnn
     { abx@fid@ \tl_to_str:n {#2} @ \tl_to_str:n {#3} } {#4}{#5}{#6}
   }
   {
    \xpatch_main_three:Ncnnn \xpatch_pretocmd_once:Nnnn
     { abx@fid@ \tl_to_str:n {#2} @ \tl_to_str:n {#3} } {#4}{#5}{#6}
   }
 }
\NewDocumentCommand{\xapptoindexfieldformat} { s O{*} +m +m +m +m }
 {
  \IfBooleanTF{#1}
   {
    \xpatch_main_three:Ncnnn \xpatch_apptocmd_all:Nnnn
     { abx@fid@ \tl_to_str:n {#2} @ \tl_to_str:n {#3} } {#4}{#5}{#6}
   }
   {
    \xpatch_main_three:Ncnnn \xpatch_apptocmd_once:Nnnn
     { abx@fid@ \tl_to_str:n {#2} @ \tl_to_str:n {#3} } {#4}{#5}{#6}
   }
 }
\NewDocumentCommand{\xpatchindexfieldformat} { s O{*} +m +m +m +m +m }
 {
  \IfBooleanTF{#1}
   {
    \xpatch_main_four:Ncnnnn \xpatch_patchcmd_all:Nnnnn
     { abx@fid@ \tl_to_str:n {#2} @ \tl_to_str:n {#3} } {#4}{#5}{#6}{#7}
   }
   {
    \xpatch_main_four:Ncnnnn \xpatch_patchcmd_once:Nnnnn
     { abx@fid@ \tl_to_str:n {#2} @ \tl_to_str:n {#3} } {#4}{#5}{#6}{#7}
   }
 }
\NewDocumentCommand{\regexpatchindexfieldformat} { s O{*} +m +m +m +m +m }
 {
  \IfBooleanTF{#1}
   {
    \xpatch_main_four:Ncnnnn \xpatch_regexpatchcmd_all:Nnnnn
     { abx@fid@ \tl_to_str:n {#2} @ \tl_to_str:n {#3} } {#4}{#5}{#6}{#7}
   }
   {
    \xpatch_main_four:Ncnnnn \xpatch_regexpatchcmd_once:Nnnnn
     { abx@fid@ \tl_to_str:n {#2} @ \tl_to_str:n {#3} } {#4}{#5}{#6}{#7}
   }
 }

\NewDocumentCommand{\xshowindexnameformat} { s O{*} +m }
 {
  \IfBooleanT{#1}
   {
    \group_begin:
    \bool_set_true:N \l_xpatch_tracing_bool
   }
  \xpatch_main_zero:Nc \cs_show:N { abx@nid@ \tl_to_str:n {#1} @ \tl_to_str:n {#2} }
  \IfBooleanT{#1}
   {
    \group_end:
   }
 }
\NewDocumentCommand{\xpretoindexnameformat} { s O{*} +m +m +m +m }
 {
  \IfBooleanTF{#1}
   {
    \xpatch_main_three:Ncnnn \xpatch_pretocmd_all:Nnnn
     { abx@nid@ \tl_to_str:n {#2} @ \tl_to_str:n {#3} } {#4}{#5}{#6}
   }
   {
    \xpatch_main_three:Ncnnn \xpatch_pretocmd_once:Nnnn
     { abx@nid@ \tl_to_str:n {#2} @ \tl_to_str:n {#3} } {#4}{#5}{#6}
   }
 }
\NewDocumentCommand{\xapptoindexnameformat} { s O{*} +m +m +m +m }
 {
  \IfBooleanTF{#1}
   {
    \xpatch_main_three:Ncnnn \xpatch_apptocmd_all:Nnnn
     { abx@nid@ \tl_to_str:n {#2} @ \tl_to_str:n {#3} } {#4}{#5}{#6}
   }
   {
    \xpatch_main_three:Ncnnn \xpatch_apptocmd_once:Nnnn
     { abx@nid@ \tl_to_str:n {#2} @ \tl_to_str:n {#3} } {#4}{#5}{#6}
   }
 }
\NewDocumentCommand{\xpatchindexnameformat} { s O{*} +m +m +m +m +m }
 {
  \IfBooleanTF{#1}
   {
    \xpatch_main_four:Ncnnnn \xpatch_patchcmd_all:Nnnnn
     { abx@nid@ \tl_to_str:n {#2} @ \tl_to_str:n {#3} } {#4}{#5}{#6}{#7}
   }
   {
    \xpatch_main_four:Ncnnnn \xpatch_patchcmd_once:Nnnnn
     { abx@nid@ \tl_to_str:n {#2} @ \tl_to_str:n {#3} } {#4}{#5}{#6}{#7}
   }
 }
\NewDocumentCommand{\regexpatchindexnameformat} { s O{*} +m +m +m +m +m }
 {
  \IfBooleanTF{#1}
   {
    \xpatch_main_four:Ncnnnn \xpatch_regexpatchcmd_all:Nnnnn
     { abx@nid@ \tl_to_str:n {#2} @ \tl_to_str:n {#3} } {#4}{#5}{#6}{#7}
   }
   {
    \xpatch_main_four:Ncnnnn \xpatch_regexpatchcmd_once:Nnnnn
     { abx@nid@ \tl_to_str:n {#2} @ \tl_to_str:n {#3} } {#4}{#5}{#6}{#7}
   }
 }

\NewDocumentCommand{\xshowindexlistformat} { s O{*} +m }
 {
  \IfBooleanT{#1}
   {
    \group_begin:
    \bool_set_true:N \l_xpatch_tracing_bool
   }
  \xpatch_main_zero:Nc \cs_show:N { abx@lid@ \tl_to_str:n {#1} @ \tl_to_str:n {#2} }
  \IfBooleanT{#1}
   {
    \group_end:
   }
 }
\NewDocumentCommand{\xpretoindexlistformat} { s O{*} +m +m +m +m }
 {
  \IfBooleanTF{#1}
   {
    \xpatch_main_three:Ncnnn \xpatch_pretocmd_all:Nnnn
     { abx@lid@ \tl_to_str:n {#2} @ \tl_to_str:n {#3} } {#4}{#5}{#6}
   }
   {
    \xpatch_main_three:Ncnnn \xpatch_pretocmd_once:Nnnn
     { abx@lid@ \tl_to_str:n {#2} @ \tl_to_str:n {#3} } {#4}{#5}{#6}
   }
 }
\NewDocumentCommand{\xapptoindexlistformat} { s O{*} +m +m +m +m }
 {
  \IfBooleanTF{#1}
   {
    \xpatch_main_three:Ncnnn \xpatch_apptocmd_all:Nnnn
     { abx@lid@ \tl_to_str:n {#2} @ \tl_to_str:n {#3} } {#4}{#5}{#6}
   }
   {
    \xpatch_main_three:Ncnnn \xpatch_apptocmd_once:Nnnn
     { abx@lid@ \tl_to_str:n {#2} @ \tl_to_str:n {#3} } {#4}{#5}{#6}
   }
 }
\NewDocumentCommand{\xpatchindexlistformat} { s O{*} +m +m +m +m +m }
 {
  \IfBooleanTF{#1}
   {
    \xpatch_main_four:Ncnnnn \xpatch_patchcmd_all:Nnnnn
     { abx@lid@ \tl_to_str:n {#2} @ \tl_to_str:n {#3} } {#4}{#5}{#6}{#7}
   }
   {
    \xpatch_main_four:Ncnnnn \xpatch_patchcmd_once:Nnnnn
     { abx@lid@ \tl_to_str:n {#2} @ \tl_to_str:n {#3} } {#4}{#5}{#6}{#7}
   }
 }
\NewDocumentCommand{\regexpatchindexlistformat} { s O{*} +m +m +m +m +m }
 {
  \IfBooleanTF{#1}
   {
    \xpatch_main_four:Ncnnnn \xpatch_regexpatchcmd_all:Nnnnn
     { abx@lid@ \tl_to_str:n {#2} @ \tl_to_str:n {#3} } {#4}{#5}{#6}{#7}
   }
   {
    \xpatch_main_four:Ncnnnn \xpatch_regexpatchcmd_once:Nnnnn
     { abx@lid@ \tl_to_str:n {#2} @ \tl_to_str:n {#3} } {#4}{#5}{#6}{#7}
   }
 }
\NewDocumentCommand{\checkpatchable}{ +m }
 {
  \group_begin:
  \bool_set_true:N \l_xpatch_tracing_bool
  \xpatch_check_patchable:N #1
  \group_end:
 }
\cs_generate_variant:Nn \xpatch_get_all:N {c}
\cs_generate_variant:Nn \xpatch_rebuild:N {c}
\NewDocumentCommand{\xpatchoptarg}{ +m +m }
 {
  \xpatch_main_check:N #1
  \bool_if:NTF \l_xpatch_optional_bool
   {
    \tl_set:Nx \l_xpatch_name_tl { \tl_tail:V \l_xpatch_name_tl }
    \tl_set:Nf \l_xpatch_prefix_tl { \token_get_prefix_spec:N #1 }
    \tl_clear:N \l_xpatch_prefix_tl
    \tl_set_rescan:Nnx \l_xpatch_prefix_tl { } \l_xpatch_prefix_tl
    \tl_set_eq:Nc \l_xpatch_replacement_tl { \l_xpatch_name_tl }
    \tl_set:Nn \l_tmpa_tl { { #2 } }
    \regex_replace_once:nnN { \cB. .* \cE. \Z} { \u{l_tmpa_tl} }
     \l_xpatch_replacement_tl
    \xpatch_rebuild:c { \l_xpatch_name_tl }
   }
   {
    \group_begin:
    \bool_set_true:N \l_xpatch_tracing_bool
    \xpatch_message:n
     {
      Macro~`\token_to_str:N #1'~ has~no~optional~argument~
      or~it~has~been~defined~with~`xparse'~and~operating~
      on~such~commands~is~(still)~not~supported
     }
    \group_end:
   }
 }
\NewDocumentCommand{\tracingxpatches}{ O{1} }
 {
  \int_compare:nTF { #1 > 0 }
   { \bool_set_true:N \l_xpatch_tracing_bool }
   { \bool_set_false:N \l_xpatch_tracing_bool }
 }
\NewDocumentCommand{\xpatchparametertext}{ +m +m +m +m +m }
 {
  \xpatch_check_patchable:N #1
  \bool_if:NTF \l_xpatch_patchable_bool
   {
    \regex_replace_once:nnN { #2 } { #3 } \l_xpatch_arg_tl
    \xpatch_rebuild:N #1
    #4
   }
   {
    #5
   }
 }
%% 
%%
%% End of file `regexpatch.sty'.
