| gsubsti |
(String subinfo, Regexp re, String target) |
yoix.re |
| gsubsti |
(String subinfo, String re_pattern, String target) |
|
| |
Replaces all portions of the
target
string matched by the regular expression
re
according to the substitution information provided by
subinfo.
In the simplest case, each match made by
re
in the
target
will be directly replaced by the contents of
subinfo.
However, if the regular expression contains grouping information (i.e.,
sub-expressions enclosed by parentheses), then the portion of
target
matched by a sub-expression can be referenced in
subinfo
by means of a backslash-number sequence (i.e., \n, where
n
is the number of the sub-expression, counting in order from left to right
within the regular expression, that made the match).
Moreover, either
n
equal to 0 or an ampersand
(&)
refers to the entire match made by the regular expression.
When no substitutions are made, then
target
itself is returned, otherwise a new string containing the substitutions is
returned.
Consequently, it is possible to test for the occurrence of substitutions by
using simple equality to test the string value returned by the
gsubsti
call against the original
target
string value.
| |
| Example: |
The following script turns all instances of the word "the" in the Yoix
home page into three asterisks regardless of case.
import yoix.io.*;
import yoix.re.*;
import yoix.stdio.*;
Regexp re;
String line;
String result;
Stream page =
open("http://www.research.att.com/sw/tools/yoix/", "r");
re.pattern = "(^|[^a-zA-Z0-9])the([^a-zA-Z0-9]|$)";
re.type |= CASE_INSENSITIVE;
while(line = page.nextline) {
result = gsubsti("\\1***\\2", re, line);
if(result != line)
printf("Before: %s\nAfter: %s\n", line, result);
}
One portion of the result on standard output might look something like:
Before: The Yoix interpreter supports the important data types and
After: *** Yoix interpreter supports *** important data types and
Refer to the documentation on
Subexp
for related examples.
| | |
| Return: |
String
| | |
| See Also: |
gvsubsti,
regexec,
Regexp,
regexp,
regsub,
Subexp,
substi,
vsubsti
|
|
Yoix is a registered trademark of AT&T Intellectual Property.
|