Core Function RegexUnescape

From Sputnik Wiki
Jump to: navigation, search
RegexUnescape( <expression> )

Contents

Description

Remove any escapes from regular expression characters.

RegexUnescape() takes a string and removes any backslash in front of every character that is part of the regular expression syntax.

Parameters

expression

The string to use.

Return Value

Success: Returns the escaped string.

Failure: Returns empty string and throws an exception.

Remarks

If an escaped character in the string is not a Regexp compatible character then an empty string will be returned unmodified and an exception will be thrown.

Because this throws an exception on an invalid character to unescape it is NOT recommend you use this to remove escapes from just any random string.

For that purpose you should use Unescape( <expression> ) instead.

Example

// Obviously using @"" is the best way use Regexp strings
say @"(\w+)\s(\1)";                             // Prints: (\w+)\s(\1)
say RegexEscape(@"(\w+)\s(\1)");                // Prints: \(\\w\+\)\\s\(\\1\)
say RegexUnEscape(RegexEscape(@"(\w+)\s(\1)")); // Prints: (\w+)\s(\1)

Using @Error

say RegexUnEscape(@"\m");
if(@Error)
{
	say "There was an error parsing";
	say @ErrorMsg;
}
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox