replaceFirst

replaceFirst(text:         String;
             replacements: String;
             pattern:      String;
             ignoreCase:   Boolean): String;

The replaceFirst method of the JadeRegex class replaces only the first occurrence (if any) of the specified pattern in the specified text with the replacement text. This method returns the replacement string or it returns the original text if there is no successful match.

The replaceFirst method parameters are described in the following table.

Parameter Description
text Text string within which your want to replace text
replacements

Text with which to replace the first match

pattern Regex pattern string
ignoreCase Specifies whether matching is case-sensitive

The following is an example of a replaceFirst type method.

typeReplaceFirst();
vars
    text, pattern, replacement : String;
begin
    text := "<p>lorem ipsom</p><p>paragraph2</p>";
    pattern := "<p>[^<]*</p>";
    replacement := '<p>paragraph1</p>';
    write JadeRegex@replaceFirst(text, replacement, pattern, true);
    /* writes <p>paragraph1</p><p>paragraph2</p> */
end;

2020.0.01 and higher