SBM ModScript Reference → Programming SBM ModScript → Object Types → Regex → Regex ReplaceFirst() Method
Replaces the first matched part of a string with a replacement value using the compiled regex.
| Parameter | Type | Description |
|---|---|---|
|
value |
string |
The string to be searched. |
|
replacement |
string |
The value inserted into the string in the first matched location. |
| Type | Description |
|---|---|
|
string |
A string where the first match for the compiled Regex in "value" is replaced with "replacement". |
SBM ModScript version: 11.6.1.
var r = Regex(); // Regex object 'r'
r.Compile("\\d+"); // Compile regex expression "\d+"
var changed = r.ReplaceFirst("12ab3d456e78", "ABC");
// Replace the first group of digits in the string "value" with the replacement string
Ext.WriteStream( changed );
Result:
ABCab3d456e78
None.
Copyright © 2007–2020 Micro Focus or one of its affiliates. All rights reserved.