Institut für Astronomie und AstrophysikAbteilung AstronomieSand 1, D-72076 Tübingen, Germany |
strepex
Performs replacements of parts in strings by using regular expressions (REPlacement of regular EXpressions). Subexpressions may be also inserted into the replacement string.
String processing
newstring = strepex( string, expression, [replacement], /fold_case, /all)
string - the string which will be analyzed and whose parts will be replaced in return. expression - A regular expression as being used for the REGEX function. Subexpressions must be given in parentheses. replacement - String to replace for matching regular expressions. If it contains "&n" it will be replaced with the n-th subexpression in expression above (starting from 0). "&" may be escaped with "\&", "\" with "\\". If not given replacement will be empty string (deletion of string).
fold_case - Use case-insensitive regular expression matching. But replacement remains case sensitive. all - Replace all occurrences of expression in given string. Default is to replace only the first occurrence of expression.
Returns the input string with a replacement of all occurrences of a matching expression by the replacement (which in turn may contain replacements of subexpressions). If no subexpression was found the input string remains unaltered.
Do not use in time critical sections: It involves lot of looping on input and replacement string (but the recursion mentioned in earlier versions was replaced to allow escaping).
s = "x5*y3+2" s1 = strepex(s,"(x|y)([0-9])","&0(&1)",/all) -> s1 contains "x(5)*y(3)+2"
$Log: strepex.pro,v $ Revision 1.5 2004/06/30 07:15:46 goehler replace of subexpression expansion (&n -> n-th subexpression) with a more elaborated but quirky version which now supports escaping within replacement string. Revision 1.4 2004/06/29 07:55:01 goehler added: internal noexpand keyword which fastens up the subexpression expansion waiver: implementation of escaping using "\" is wrong. must be replaced with something else Revision 1.3 2003/04/09 13:03:37 goehler updated documentation/fix of example bug Revision 1.2 2002/09/10 07:01:51 goehler typos/fixed aitlib html style Revision 1.1 2002/09/04 14:59:26 goehler string function to perform regular expression replacements.
[Home Page] [Software, Documentation] [IDL Documentation] [Quick Reference] [Feedback]