Core Function RegexUnescape
From Sputnik Wiki
(Difference between revisions)
(Created page with "<pre> RegexUnescape( <expression> ) </pre> === Description === Remove any escapes from regular expression characters. RegexUnescape() takes a string and removes any backslash ...") |
|||
Line 19: | Line 19: | ||
Success: Returns the escaped string. | Success: Returns the escaped string. | ||
− | Failure: Returns empty string and | + | Failure: Returns empty string and throws an exception. |
=== Remarks === | === Remarks === | ||
− | If an escaped character in the string is not a Regexp compatible character then an empty string will be returned unmodified and | + | 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 [[Core Function Unescape|Unescape( <expression> )]] instead. | ||
=== Example === | === Example === |
Revision as of 15:07, 13 September 2013
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; }