snipt

Ctrl+h for KB shortcuts
#13451

ActionScript 3

Email RegExp

1
2
3
var pattern:RegExp = (\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,6});

// PHP return preg_match('/^[A-Za-z0-9\._\-+]+@[A-Za-z0-9_\-+]+(\.[A-Za-z0-9_\-+]+)+$/', $value);
https://snipt.net/embed/34784f2fbd51f8a27ce54505e57b075c/
https://snipt.net/raw/34784f2fbd51f8a27ce54505e57b075c/
34784f2fbd51f8a27ce54505e57b075c
as3
ActionScript 3
3
2014-04-15T13:54:55
True
False
/api/public/snipt/13451/
email-regexp
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="kd">var</span> <span class="n">pattern</span><span class="p">:</span><span class="kt">RegExp</span> <span class="o">=</span> <span class="o">(\</span><span class="n">w</span><span class="o">+</span><span class="err">@</span><span class="o">[</span><span class="n">a</span><span class="o">-</span><span class="n">zA</span><span class="o">-</span><span class="n">Z_</span><span class="o">]+?\.[</span><span class="n">a</span><span class="o">-</span><span class="n">zA</span><span class="o">-</span><span class="n">Z</span><span class="o">]{</span><span class="mi">2</span><span class="o">,</span><span class="mi">6</span><span class="o">});</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="c1">// PHP return preg_match(&#39;/^[A-Za-z0-9\._\-+]+@[A-Za-z0-9_\-+]+(\.[A-Za-z0-9_\-+]+)+$/&#39;, $value);</span> </span></pre></div> </td></tr></table>
as3, email, flash, regex
#13450

ActionScript 3

Is GIF, JPG, PNG

var pattern:RegExp = ([^\s]+(?=\.(jpg|gif|png))\.\2);
https://snipt.net/embed/42bfba869ffe717731ae9b223ff6f7c0/
https://snipt.net/raw/42bfba869ffe717731ae9b223ff6f7c0/
42bfba869ffe717731ae9b223ff6f7c0
as3
ActionScript 3
1
2014-04-15T18:15:17
True
False
/api/public/snipt/13450/
is-gif-jpg-png
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="kd">var</span> <span class="n">pattern</span><span class="p">:</span><span class="kt">RegExp</span> <span class="o">=</span> <span class="o">([^\</span><span class="n">s</span><span class="o">]+(?=\.(</span><span class="n">jpg</span><span class="o">|</span><span class="n">gif</span><span class="o">|</span><span class="n">png</span><span class="o">))\.\</span><span class="mi">2</span><span class="o">);</span> </span></pre></div> </td></tr></table>
as3, flash, images, regex
#13447

ActionScript 3

Find and Replace Function

1
2
3
4
5
6
7
8
function strReplace(str:String, search:String, replace:String):String {
 return str.split(search).join(replace);
}


var str:String = "Hello World!";
str = strReplace(str, "Hello", "Goodbye"); 
trace(str); //outputs Goodbye World!
https://snipt.net/embed/fce4346764506e36eb04c5ad8aa85466/
https://snipt.net/raw/fce4346764506e36eb04c5ad8aa85466/
fce4346764506e36eb04c5ad8aa85466
as3
ActionScript 3
8
2014-04-16T20:57:57
True
False
/api/public/snipt/13447/
find-and-replace-function
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a> <a href="#L-8">8</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="kd">function </span><span class="nf">strReplace</span><span class="o">(</span><span class="n">str</span><span class="o">:</span><span class="kt">String</span><span class="o">,</span> <span class="n">search</span><span class="o">:</span><span class="kt">String</span><span class="o">,</span> <span class="n">replace</span><span class="o">:</span><span class="kt">String</span><span class="o">):</span><span class="kt">String</span> <span class="o">{</span> </span><span id="L-2"><a name="L-2"></a> <span class="k">return</span> <span class="n">str</span><span class="o">.</span><span class="na">split</span><span class="o">(</span><span class="n">search</span><span class="o">).</span><span class="n">join</span><span class="o">(</span><span class="n">replace</span><span class="o">);</span> </span><span id="L-3"><a name="L-3"></a><span class="o">}</span> </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a> </span><span id="L-6"><a name="L-6"></a><span class="kd">var</span> <span class="n">str</span><span class="p">:</span><span class="kt">String</span> <span class="o">=</span> <span class="s2">&quot;Hello World!&quot;</span><span class="o">;</span> </span><span id="L-7"><a name="L-7"></a><span class="n">str</span> <span class="o">=</span> <span class="n">strReplace</span><span class="o">(</span><span class="n">str</span><span class="o">,</span> <span class="s2">&quot;Hello&quot;</span><span class="o">,</span> <span class="s2">&quot;Goodbye&quot;</span><span class="o">);</span> </span><span id="L-8"><a name="L-8"></a><span class="nf">trace</span><span class="o">(</span><span class="n">str</span><span class="o">);</span> <span class="c1">//outputs Goodbye World!</span> </span></pre></div> </td></tr></table>
as3, find, flash, replace
#13446

ActionScript 3

RegEx - Find and Replace

1
2
3
4
5
var str:String = "Hello World!";

var myPattern:RegExp = /Hello/g; //regex to remove all hellos
str = str.replace(myPattern, "Goodbye");
trace(str); // Goodbye World!
https://snipt.net/embed/686b16894fc75ddb127efd92c4d92ca9/
https://snipt.net/raw/686b16894fc75ddb127efd92c4d92ca9/
686b16894fc75ddb127efd92c4d92ca9
as3
ActionScript 3
7
2014-04-17T11:54:29
True
False
/api/public/snipt/13446/
regex-find-and-replace
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="kd">var</span> <span class="n">str</span><span class="p">:</span><span class="kt">String</span> <span class="o">=</span> <span class="s2">&quot;Hello World!&quot;</span><span class="o">;</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="kd">var</span> <span class="n">myPattern</span><span class="p">:</span><span class="kt">RegExp</span> <span class="o">=</span> <span class="sr">/Hello/g; //</span><span class="n">regex</span> <span class="n">to</span> <span class="n">remove</span> <span class="n">all</span> <span class="n">hellos</span> </span><span id="L-4"><a name="L-4"></a><span class="n">str</span> <span class="o">=</span> <span class="n">str</span><span class="o">.</span><span class="na">replace</span><span class="o">(</span><span class="n">myPattern</span><span class="o">,</span> <span class="s2">&quot;Goodbye&quot;</span><span class="o">);</span> </span><span id="L-5"><a name="L-5"></a><span class="nf">trace</span><span class="o">(</span><span class="n">str</span><span class="o">);</span> <span class="c1">// Goodbye World!</span> </span></pre></div> </td></tr></table>
as3, find, flash, regex, replace, string