pwRegexpRep


 s = pwRegexpRep(string, pattern, replace, simplePattern, verbose)

 Replaces all occurrences of the pattern in a string using the PottersWheel
 convention for simplified regular expressions.

 

Arguments for pwRegexpRep

 string         String to be replaced.
 pattern        Either a simple PottersWheel regular expression or a valid
                regular expression. If no matches are found, the string is
                returned unchanged.
 replace        Simplified replacement string where e.g. "<1>" corresponds to
                "<1:...>" in the given pattern and will be converted internally
                to "$<T1>" before the replacement is applied by calling regexprep.
 simplePattern  If true (default), the pattern is assumed to be a PottersWheel
                simple regular expression like "Epo_+" which will be converted
                automatically to a valid regular expression based on the
                PottersWheel naming convention, here
                "Epo_([a-z0-9]*[A-Z]+[a-zA-Z0-9]*)".
                With simplePattern = false, the pattern is assumed to
                be already a valid regular expression and is not converted.
                This may be useful if the function pwSimpleToValidRegExp
                has already been called for the provided pattern.
 verbose        If true, the valid regular expression is displayed as a
                debugging information. Default: false


 

Approach

 1. Does the pattern match the original string?
    If not, the original string is copied directly to the replaced string.
 2. The pattern may comprise named groups like "<1:R|pR>", internally "(?<T1>R|pR)",
    which matches "R" and "pR" and may be used in the replacement
    by "<1>", internally "$<T1>".
 3. The original string is replaced based on the potentially converted
    pattern using the converted replacement string in the
    same fashion as in the Matlab function regexprep.

 

Example

 string:                acR_ATP_o_o
 pattern:               <1:acR|inR>_ATP_<2:o|PTP>_o
 converted pattern:     ^(?<T1>acR|inR)_ATP_(?<T2>o|PTP)_o$
 replacement:           <1>_o_<2>_P
 converted replacement: $<T1>_o_$<T2>_P
 result:                acR_o_o_P

 % Using the simple pattern approach
 result = pwRegexpRep('acR_ATP_o_o', '<1:acR|inR>_ATP_<2:o|PTP>_o', '<1>_o_<2>_P')

 % Using the valid regular expression approach
 simplePattern = false;
 result = pwRegexpRep('acR_ATP_o_o', '^(?<T1>acR|inR)_ATP_(?<T2>o|PTP)_o$', ...
                      '<1>_o_<2>_P', simplePattern)

See also

pwSimpleToValidRegExp
pwTutorial_Rule_based_modeling
regexprep