GSAK (Geocaching Swiss Army Knife)
Contents - Index

RegExEscape (function)

RegExEscape(sData) : string

sData - The regular expression to escape

It can be difficult when using a regex to search because your search string may contain "special" characters that have special meaning to the regular expression. When you want these special characters to be used as plain text for your search you must remember to escape them. This can get confusing if your search string is large, and difficult if your search string is coming from another source and is not a literal in your code. RegexEscape to the rescue. This function will completely escape a string so it can be used in a regular expression and you can be sure the whole string will now be treated as plain text regardless of any special characters within.

For example to search for "1+1.5" as literal text, use:
 

$RegExSearch = RegExEscape("1+1.5")
$count = RegExCount($RegExSearch,$data)

 
Note: $RegExSearch = "1\+1\.5"

Alpha List         Category List
Copyright 2004-2019 CWE Computer Services  
Privacy Policy Contact