Regex ReplaceFirst() Method

Replaces the first matched part of a string with a replacement value using the compiled regex.

Function Signature

 string ReplaceFirst( string value, string replacement )

Parameters

Parameter Type Description

value

string

The string to be searched.

replacement

string

The value inserted into the string in the first matched location.

Return

Type Description

string

A string where the first match for the compiled Regex in "value" is replaced with "replacement".

Technical Details

SBM ModScript version: 11.6.1.

Example

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

Notes

None.

Related Topics

Regex