Replace all: Difference between revisions
Jump to navigation
Jump to search
imported>Bale Created page with '{{ #vardefine:name|replace_all}}{{ #vardefine:return_type|string}}{{ FunctionPage| name={{#var:name}}| function_category=String Handling Routines| function1={{Function| name={{…' |
imported>Coderanger Add note about $n. |
||
(One intermediate revision by one other user not shown) | |||
Line 5: | Line 5: | ||
FunctionPage| | FunctionPage| | ||
name={{#var:name}}| | name={{#var:name}}| | ||
function1={{Function| | function1={{Function| | ||
Line 18: | Line 17: | ||
}}| | }}| | ||
function_description=This function first resets the matcher {{pspan|pattern}}. It then scans the input sequence looking for matches of the pattern. Characters that are not part of any match are appended directly to the result string with each match replaced by the replacement string.| | function_description=This function first resets the matcher {{pspan|pattern}}. It then scans the input sequence looking for matches of the pattern. Characters that are not part of any match are appended directly to the result string with each match replaced by the replacement string. Captured groups can be used in the replacement string via $0, $1, etc.| | ||
code1={{CodeSample| | code1={{CodeSample| | ||
Line 36: | Line 35: | ||
{{SeeAlso|replace_first}}| | {{SeeAlso|replace_first}}| | ||
}} | }} | ||
[[Category:String Handling Routines]] |
Latest revision as of 01:03, 4 January 2015
Function Syntax
string replace_all(matcher pattern ,string replacement )
- pattern is the regular expression to use
- replacement is used to replace any match of the pattern
This function first resets the matcher pattern. It then scans the input sequence looking for matches of the pattern. Characters that are not part of any match are appended directly to the result string with each match replaced by the replacement string. Captured groups can be used in the replacement string via $0, $1, etc.
Simple Example
For example:
string input = "aabfooaaaabfooabfoob";
matcher test_match = create_matcher("a*b", input);
string result = replace_all(test_match, "-");
print(result);
Will result in the following being printed:
-foo-foo-foo-