Find & Replace Commands
This page uses Hashtag Replace commands to demonstrates altering Variable values.
For case insensitive matching, tag any of these before the search string: case insensitive, insensitive, ci, i.
For regular expression pattern matching, tag any of these before the search string: pattern, regular expression, regex, re.
Simple String Find & Replace
Processing this Hashtag Markup:
<#
set my_var to "the quick brown fox jumps over the lazy dog";
replace "brown" in my_var with "green";
replace case insensitive "DOG" in my_var with "cat";
#>
Note: Hashtag Markup is shown below <# in bold #>.
The value generated by processing the Hashtag Markup, and applying any Variable Contexts, is injected into this HTML page after the ⇒ symbol.
<#[my_var]#> ⇒ the quick green fox jumps over the lazy cat
Regular Expression Find & Replace
Processing this Hashtag Markup:
<#
set my_var to "the quick brown fox jumps over the lazy dog";
replace pattern "(brown|lazy)" in my_var with "nice";
#>
<#[my_var]#> ⇒ the quick nice fox jumps over the nice dog
Referrer Processing
Processing this Hashtag Markup:
Remove a GET variable from the referring URL
<#
set referrer to "<#[system.referrer]#>";
replace pattern "&remove=(.*?)(&|$)" in referrer with "&";
replace pattern "\?remove=(.*?)(&|$)" in referrer with "?";
#>
<#[system.referrer as html]#> ⇒ | |
<#[referrer as html]#> ⇒ | |
URL Cleansing
Processing this Hashtag Markup:
<#
set dirty_url to "https://hashtagfoundation.org?&&&var=value&&&message=test&&&";
replace pattern "&+" in dirty_url with "&";
replace pattern "&$" in dirty_url with "";
replace "?&" in dirty_url with "?";
replace pattern "^[^\?]+$" in dirty_url with "<#[dirty_url]#>?";
#>
<#[dirty_url]#> ⇒ https://hashtagfoundation.org?var=value&message=test