regex_replace (MathScript RT Module Function)

LabVIEW 2012 MathScript RT Module Help

Edition Date: June 2012

Part Number: 373123C-01

»View Product Info
Download Help (Windows Only)

Owning Class: string

Requires: MathScript RT Module


c = regex_replace(a, format, b)

c = regex_replace(a, format, b, option)

c = regex_replace(a, format, b, n)

Legacy Name: regexprep


Searches for a regular expression in the input string a and replaces the matched string with string b.




Name Description
a Specifies the string in which you want to perform a string replacement.
format Specifies the pattern for which you want to search in a.
b Specifies the string that replaces each matched string in a.
option Specifies additional options for the search and replace operation. option is a string that accepts the following values.

'ignorecase' (default) Ignores the case when searching.
'once' Replaces only the first matched string.
'preservecase' Ignores the case when searching. However, LabVIEW preserves the case of the matched string in a and overrides the characters in b with the original case.
n Directs LabVIEW to replace only the first n matched strings. If you do not specify n, LabVIEW replaces all matched strings in a.


Name Description
c Returns the edited string with the replaced characters.


If you specify 'preservecase', the matched string in a must follow one of the following capitalization patterns:
  • The first letter is uppercase, as in Labview
  • All letters are uppercase, as in LABVIEW
  • All letters are lowercase, as in labview
If the matched string uses a different capitalization pattern, such as LabVIEW, LabVIEW uses the 'ignorecase' option instead of the 'preservecase' option.

The following table lists the support characteristics of this function.

Supported in the LabVIEW Run-Time Engine Yes
Supported on RT targets Yes
Suitable for bounded execution times on RT Not characterized


a = 'Run regex_replace in LabVIEW MathScript';
format = 'L[a-zA-Z]+W';
c1 = regex_replace(a, format, 'MathScript')

a = 'Run regex_replace in LabVIEW MathScript';
format = 'L[a-z]+W';
c2 = regex_replace(a, format, 'MathScript', 'ignorecase')
c3 = regex_replace(a, format, 'MathScript', 'preservecase')

a = 'Run regex_replace in LABVIEW MathScript';
format = 'L[a-z]+W';
c4 = regex_replace(a, format, 'MathScript', 'preservecase')

Related Topics



Not Helpful