StringTools
RegSubs
perform regular expression substitutions
Calling Sequence
Parameters
Description
Examples
RegSubs( env, text )
env
-
string = string; substitution to make
text
string; text to substitute into
The RegSubs(env,text) command replaces each occurrence of a substring matching the left-hand side of env with the right-hand side of env in the string text.
If no substring of text matches the left-hand side of env, then text is returned unchanged.
This procedure is closely related to StringTools[RegSub], but provides a more intuitive interface. The chief difference between the two is that RegSubs effects all relevant substitutions (serially), while StringTools[RegSub] performs a single substitution. Also, the left-hand side of env cannot match an empty substring of text. (An exception is raised in this case.)
All of the StringTools package commands treat strings as (null-terminated) sequences of 8-bit (ASCII) characters. Thus, there is no support for multibyte character encodings, such as unicode encodings.
with⁡StringTools:
RegSubs⁡((a))=gu\\1v\\2,abc
guavabc
RegSubs⁡([abc]*)d=&-\\1,abbbcd
abbbcd-abbbc
RegSubs⁡a([bc]*)(c*d)=&-\\1-\\2,abcd
abcd-bc-d
RegSubs⁡(bc+d$|ef*g.|h?i(j+k))=&-\\1-\\2,effgz
effgz-effgz-
RegSubs⁡(bc+d$|ef*g.|h?i(j|k))=&-\\1-\\2,reffgz
reffgz-effgz-
RegSubs⁡(.*)c(anad[ai])(.*)=\\1C\\2\\3,Maple is canadian
Maple is Canadian
RegSubs⁡[ \t]+= ,Some text \t\t with extra \t space.
Some text with extra space.
See Also
Regular_Expressions
string
StringTools[RegMatch]
StringTools[RegSub]
StringTools[Substitute]
StringTools[SubstituteAll]
Download Help Document