replaceText

Typefunction
DictionaryLCS
LibraryLiveCode Script
Syntax
replaceText(<stringToChange>, <matchExpression>, <replacementString>)
Summary

Searches for a regular expression and replaces the portions that match the regular expression.

Introduced1.0
OSmac, windows, linux, ios, android
Platformsdesktop, server, mobile
Parameters
NameTypeDescription
stringToChange

A container reference or literal value.

matchExpression

A regular expression.

replacementString

A container reference or literal value.

Example
put replaceText("malformed","mal","well") -- returns "wellformed"
-- change return-delimited text to comma-delimited
put replaceText(field "Stats",return,comma) into field "Stats"
put replaceText("colour or color","colou?r","culler")
-- returns "culler or culler"
-- escape RegEx metacharacter using backslash
put replaceText ( "ABC|DEV" , "\|" , CR )
Values
NameTypeDescription
return

The replaceText function returns the changed string.

RelatedKeyword: string
Property: caseSensitive
Command: replace, filter
Glossary: command, regular expression, property
Description

Use the replaceText function to search for and replace text that matches a particular pattern.

The replaceText function replaces all the occurrences of the matchExpression with the replacementString. If more than one matching substring is found, the replaceText function replaces all of them.

The replaceText function is not as fast as the replace command, but is more flexible because you can search for any text that matches a regular expression.

The stringToChange and matchExpression are always case-sensitive, regardless of the setting of the caseSensitive property. (If you need to make a case-insensitive comparison, use "(?i)" at the start of the matchExpression to make the match case-insensitive.)

Note: A number of characters in regular expressions have special meanings and these need to be 'escaped' using backslashes ("\"). For example period (".") matches any character, so in order to replace period characters using a regular expression use ".", to replace vertical bar characters ("|") use "|" and so on. For more information on regular expressions see the Perl documentation
at http://perldoc.perl.org/perlre.html .

Tagstext processing