<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>FLEX{er} &#187; Regexp</title>
	<atom:link href="http://www.flexer.info/category/regexp/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.flexer.info</link>
	<description>flex developers web corner</description>
	<lastBuildDate>Tue, 04 Oct 2011 16:23:21 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<image>
  <link>http://www.flexer.info</link>
  <url>http://www.flexer.info/favicon.ico</url>
  <title>FLEX{er}</title>
</image>
		<item>
		<title>How To Create a Wildcard Filename Search</title>
		<link>http://www.flexer.info/2008/08/08/how-to-create-a-wildcard-filename-search/</link>
		<comments>http://www.flexer.info/2008/08/08/how-to-create-a-wildcard-filename-search/#comments</comments>
		<pubDate>Fri, 08 Aug 2008 03:00:20 +0000</pubDate>
		<dc:creator>Andrei Ionescu</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[How to]]></category>
		<category><![CDATA[MXML]]></category>
		<category><![CDATA[Regexp]]></category>
		<category><![CDATA[search]]></category>
		<category><![CDATA[wildcards]]></category>

		<guid isPermaLink="false">http://www.flexer.info/?p=233</guid>
		<description><![CDATA[This article will explain how to create a wildcard search. What I mean is the following:

dir *.*

 or

dir myfile??.txt

 The old DOS searching way. The first command (if you&#8217;ll run them in Command Prompt) returns all files with extension from the current folder. The second command will return any file having its name as this: [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-right: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.flexer.info%2F2008%2F08%2F08%2Fhow-to-create-a-wildcard-filename-search%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.flexer.info%2F2008%2F08%2F08%2Fhow-to-create-a-wildcard-filename-search%2F" height="61" width="51" /></a></div><div style="float: right; margin-right: 10px"><a class="google_buzz"  
href="http://www.google.com/reader/link?url=http://www.flexer.info/2008/08/08/how-to-create-a-wildcard-filename-search/&title=How+To+Create+a+Wildcard+Filename+Search&srcURL=http://www.flexer.info" target="_blank" rel="nofollow"><img
src="http://www.flexer.info/wp-content/plugins/google-buzz-button-for-wordpress/images/google-buzz.png" alt="Google Buzz" /></a></div><p>This article will explain how to create a wildcard search. What I mean is the following:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">dir</span> <span style="color: #339933;">*.*</span></pre></div></div>

<p> or</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">dir</span> myfile??<span style="color: #339933;">.</span>txt</pre></div></div>

<p> The old DOS searching way. The first command (if you&#8217;ll run them in Command Prompt) returns all files with extension from the current folder. The second command will return any file having its name as this: myfile00.txt, myfilecc.txt or myfile_t.txt.</p>
<p>Take a look at the following application:<br />

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_wildcards_1522667019"
			class="flashmovie"
			width="400"
			height="300">
	<param name="movie" value="/wp-content/uploads/2008/08/wildcards.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/wp-content/uploads/2008/08/wildcards.swf"
			name="fm_wildcards_1522667019"
			width="400"
			height="300">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object><br />
Clicking on the Filter button or pressing Enter key on the text input will apply the wildcard string onto the list bellow.</p>
<p>This is the entire code. Is commented and well explained but even though you may need some knowledge about Regular Expressions (or Regexp).</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>?<span style="color: #0066CC;">xml</span> <span style="color: #0066CC;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;</span>mx:Application xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> 
    layout=<span style="color: #ff0000;">&quot;absolute&quot;</span> creationComplete=<span style="color: #ff0000;">&quot;init()&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;400&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;200&quot;</span><span style="color: #66cc66;">&gt;</span>
    <span style="color: #66cc66;">&lt;</span>mx:Label x=<span style="color: #ff0000;">&quot;10&quot;</span> y=<span style="color: #ff0000;">&quot;12&quot;</span> <span style="color: #0066CC;">text</span>=<span style="color: #ff0000;">&quot;Wildcard string:&quot;</span><span style="color: #66cc66;">/&gt;</span>
    <span style="color: #66cc66;">&lt;</span>mx:TextInput id=<span style="color: #ff0000;">&quot;search&quot;</span> x=<span style="color: #ff0000;">&quot;110&quot;</span> y=<span style="color: #ff0000;">&quot;10&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;207&quot;</span> 
        keyUp=<span style="color: #ff0000;">&quot;handleDoSearch(event)&quot;</span><span style="color: #66cc66;">/&gt;</span>
    <span style="color: #66cc66;">&lt;</span>mx:<span style="color: #0066CC;">Button</span> x=<span style="color: #ff0000;">&quot;325&quot;</span> y=<span style="color: #ff0000;">&quot;10&quot;</span> label=<span style="color: #ff0000;">&quot;Filter&quot;</span> click=<span style="color: #ff0000;">&quot;handleDoSearch(event)&quot;</span><span style="color: #66cc66;">/&gt;</span>
    <span style="color: #66cc66;">&lt;</span>mx:DataGrid x=<span style="color: #ff0000;">&quot;10&quot;</span> y=<span style="color: #ff0000;">&quot;40&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;380&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;150&quot;</span> dataProvider=<span style="color: #ff0000;">&quot;{dataGridData}&quot;</span><span style="color: #66cc66;">&gt;</span>
        <span style="color: #66cc66;">&lt;</span>mx:columns<span style="color: #66cc66;">&gt;</span>
            <span style="color: #66cc66;">&lt;</span>mx:DataGridColumn headerText=<span style="color: #ff0000;">&quot;Filename&quot;</span> dataField=<span style="color: #ff0000;">&quot;@filename&quot;</span><span style="color: #66cc66;">/&gt;</span>
            <span style="color: #66cc66;">&lt;</span>mx:DataGridColumn headerText=<span style="color: #ff0000;">&quot;Size&quot;</span> dataField=<span style="color: #ff0000;">&quot;@size&quot;</span><span style="color: #66cc66;">/&gt;</span>
            <span style="color: #66cc66;">&lt;</span>mx:DataGridColumn headerText=<span style="color: #ff0000;">&quot;Date&quot;</span> dataField=<span style="color: #ff0000;">&quot;@date&quot;</span><span style="color: #66cc66;">/&gt;</span>
        <span style="color: #66cc66;">&lt;/</span>mx:columns<span style="color: #66cc66;">&gt;</span>
    <span style="color: #66cc66;">&lt;/</span>mx:DataGrid<span style="color: #66cc66;">&gt;</span>
    <span style="color: #66cc66;">&lt;</span>mx:Script<span style="color: #66cc66;">&gt;</span>
        <span style="color: #66cc66;">&lt;!</span><span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span>
&nbsp;
            <span style="color: #808080; font-style: italic;">// variable binded to the data grid</span>
            <span style="color: #808080; font-style: italic;">// this is the variable that we will modify</span>
            <span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span>
            <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> dataGridData:XMLList = <span style="color: #000000; font-weight: bold;">new</span> XMLList<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
            <span style="color: #808080; font-style: italic;">// base data - this variable will not be modified</span>
            <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> dataGridStartData:<span style="color: #0066CC;">XML</span> = 
                <span style="color: #66cc66;">&lt;</span>root<span style="color: #66cc66;">&gt;</span>
                    <span style="color: #66cc66;">&lt;</span>row filename=<span style="color: #ff0000;">&quot;file_cc&quot;</span> <span style="color: #0066CC;">size</span>=<span style="color: #ff0000;">&quot;123&quot;</span> <span style="color: #0066CC;">date</span>=<span style="color: #ff0000;">&quot;2008-08-07&quot;</span> <span style="color: #66cc66;">/&gt;</span>
                    <span style="color: #66cc66;">&lt;</span>row filename=<span style="color: #ff0000;">&quot;file_b&quot;</span> <span style="color: #0066CC;">size</span>=<span style="color: #ff0000;">&quot;12&quot;</span> <span style="color: #0066CC;">date</span>=<span style="color: #ff0000;">&quot;2008-08-08&quot;</span> <span style="color: #66cc66;">/&gt;</span>
                    <span style="color: #66cc66;">&lt;</span>row filename=<span style="color: #ff0000;">&quot;file_a&quot;</span> <span style="color: #0066CC;">size</span>=<span style="color: #ff0000;">&quot;56&quot;</span> <span style="color: #0066CC;">date</span>=<span style="color: #ff0000;">&quot;2008-08-01&quot;</span> <span style="color: #66cc66;">/&gt;</span>
                    <span style="color: #66cc66;">&lt;</span>row filename=<span style="color: #ff0000;">&quot;my_f^ile&quot;</span> <span style="color: #0066CC;">size</span>=<span style="color: #ff0000;">&quot;1786&quot;</span> <span style="color: #0066CC;">date</span>=<span style="color: #ff0000;">&quot;2008-08-01&quot;</span> <span style="color: #66cc66;">/&gt;</span>
                    <span style="color: #66cc66;">&lt;</span>row filename=<span style="color: #ff0000;">&quot;special-_$+./file&quot;</span> <span style="color: #0066CC;">size</span>=<span style="color: #ff0000;">&quot;23&quot;</span> <span style="color: #0066CC;">date</span>=<span style="color: #ff0000;">&quot;2008-08-03&quot;</span> <span style="color: #66cc66;">/&gt;</span>
                    <span style="color: #66cc66;">&lt;</span>row filename=<span style="color: #ff0000;">&quot;te<span style="color: #000099; font-weight: bold;">\\</span>s]|t_1&quot;</span> <span style="color: #0066CC;">size</span>=<span style="color: #ff0000;">&quot;899&quot;</span> <span style="color: #0066CC;">date</span>=<span style="color: #ff0000;">&quot;2008-07-04&quot;</span> <span style="color: #66cc66;">/&gt;</span>
                    <span style="color: #66cc66;">&lt;</span>row filename=<span style="color: #ff0000;">&quot;te[st_2&quot;</span> <span style="color: #0066CC;">size</span>=<span style="color: #ff0000;">&quot;777&quot;</span> <span style="color: #0066CC;">date</span>=<span style="color: #ff0000;">&quot;2008-06-04&quot;</span> <span style="color: #66cc66;">/&gt;</span>
                <span style="color: #66cc66;">&lt;/</span>root<span style="color: #66cc66;">&gt;</span>;
&nbsp;
            <span style="color: #808080; font-style: italic;">// handler for filtering</span>
            <span style="color: #808080; font-style: italic;">// used by both: button and text input</span>
            <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> handleDoSearch<span style="color: #66cc66;">&#40;</span>event:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
            <span style="color: #66cc66;">&#123;</span>
                <span style="color: #808080; font-style: italic;">// checking the event type</span>
                <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>event is MouseEvent <span style="color: #66cc66;">||</span>
                    <span style="color: #66cc66;">&#40;</span>event is KeyboardEvent <span style="color: #66cc66;">&amp;&amp;</span> 
                        <span style="color: #66cc66;">&#40;</span>event as KeyboardEvent<span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">keyCode</span> == <span style="color: #cc66cc;">13</span>
                    <span style="color: #66cc66;">&#41;</span>
                <span style="color: #66cc66;">&#41;</span>
                <span style="color: #66cc66;">&#123;</span>
                    <span style="color: #808080; font-style: italic;">// if there is at least one caracter in the text input</span>
                    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>search.<span style="color: #0066CC;">text</span>.<span style="color: #0066CC;">length</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>
                    <span style="color: #66cc66;">&#123;</span>
                        <span style="color: #808080; font-style: italic;">// reset the data grid binded variable</span>
                        dataGridData = <span style="color: #000000; font-weight: bold;">new</span> XMLList<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
                        <span style="color: #808080; font-style: italic;">// new temporary xml</span>
                        <span style="color: #000000; font-weight: bold;">var</span> tempData:<span style="color: #0066CC;">XML</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">XML</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;&lt;root&gt;&lt;/root&gt;&quot;</span><span style="color: #66cc66;">&#41;</span>;
                        <span style="color: #808080; font-style: italic;">// looping through the base data</span>
                        <span style="color: #b1b100;">for</span> each <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> item:<span style="color: #0066CC;">XML</span> <span style="color: #b1b100;">in</span> dataGridStartData.<span style="color: #006600;">children</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
                        <span style="color: #66cc66;">&#123;</span>
                            <span style="color: #808080; font-style: italic;">// matching wildcard string</span>
                            <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>matchWildcards<span style="color: #66cc66;">&#40;</span>item.<span style="color: #66cc66;">@</span>filename,search.<span style="color: #0066CC;">text</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
                            <span style="color: #66cc66;">&#123;</span>
                                <span style="color: #808080; font-style: italic;">// add a new child</span>
                                <span style="color: #000000; font-weight: bold;">var</span> tempXMLItem:<span style="color: #0066CC;">XML</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">XML</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;&lt;row&gt;&lt;/row&gt;&quot;</span><span style="color: #66cc66;">&#41;</span>;
                                tempXMLItem<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;@filename&quot;</span><span style="color: #66cc66;">&#93;</span> = item.<span style="color: #66cc66;">@</span>filename;
                                tempXMLItem<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;@size&quot;</span><span style="color: #66cc66;">&#93;</span> = item.<span style="color: #66cc66;">@</span><span style="color: #0066CC;">size</span>;
                                tempXMLItem<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;@date&quot;</span><span style="color: #66cc66;">&#93;</span> = item.<span style="color: #66cc66;">@</span><span style="color: #0066CC;">date</span>;
                                tempData.<span style="color: #0066CC;">appendChild</span><span style="color: #66cc66;">&#40;</span>tempXMLItem<span style="color: #66cc66;">&#41;</span>;
                            <span style="color: #66cc66;">&#125;</span>
                        <span style="color: #66cc66;">&#125;</span>
                        <span style="color: #808080; font-style: italic;">// set the binded data to the new found items</span>
                        dataGridData = tempData.<span style="color: #006600;">children</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
                    <span style="color: #66cc66;">&#125;</span> 
                    <span style="color: #b1b100;">else</span>
                    <span style="color: #66cc66;">&#123;</span>
                        <span style="color: #808080; font-style: italic;">// reset the binded data to base data</span>
                        dataGridData = dataGridStartData.<span style="color: #006600;">children</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
                    <span style="color: #66cc66;">&#125;</span>
                <span style="color: #66cc66;">&#125;</span>
            <span style="color: #66cc66;">&#125;</span>
&nbsp;
            <span style="color: #808080; font-style: italic;">// matching wildcard string to the string</span>
            <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> matchWildcards<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">string</span>:<span style="color: #0066CC;">String</span>, searchTerm:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Boolean</span>
            <span style="color: #66cc66;">&#123;</span>
                <span style="color: #808080; font-style: italic;">// we use regexp to search</span>
                <span style="color: #000000; font-weight: bold;">var</span> regexp:<span style="color: #0066CC;">String</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
                <span style="color: #808080; font-style: italic;">// escape special chars like: $&amp;.- which are</span>
                <span style="color: #808080; font-style: italic;">// special chars for regexp language</span>
                <span style="color: #808080; font-style: italic;">// but we won't put here * and ? which are</span>
                <span style="color: #808080; font-style: italic;">// our search characters</span>
                regexp = searchTerm.<span style="color: #006600;">replace</span><span style="color: #66cc66;">&#40;</span>
                    <span style="color: #000000; font-weight: bold;">new</span> RegExp<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;([{}<span style="color: #000099; font-weight: bold;">\(</span><span style="color: #000099; font-weight: bold;">\)</span><span style="color: #000099; font-weight: bold;">\^</span>$&amp;.<span style="color: #000099; font-weight: bold;">\/</span><span style="color: #000099; font-weight: bold;">\+</span><span style="color: #000099; font-weight: bold;">\|</span><span style="color: #000099; font-weight: bold;">\[</span><span style="color: #000099; font-weight: bold;">\\</span><span style="color: #000099; font-weight: bold;">\\</span>]|<span style="color: #000099; font-weight: bold;">\]</span>|<span style="color: #000099; font-weight: bold;">\-</span>)&quot;</span>,<span style="color: #ff0000;">&quot;g&quot;</span><span style="color: #66cc66;">&#41;</span>,<span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\\</span>$1&quot;</span><span style="color: #66cc66;">&#41;</span>;
                <span style="color: #808080; font-style: italic;">// we transform wildcards to regexp like this:</span>
                <span style="color: #808080; font-style: italic;">//   * = .*</span>
                <span style="color: #808080; font-style: italic;">//   ? = .?</span>
                regexp = regexp.<span style="color: #006600;">replace</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> RegExp<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;([<span style="color: #000099; font-weight: bold;">\*</span><span style="color: #000099; font-weight: bold;">\?</span>])&quot;</span>,<span style="color: #ff0000;">&quot;g&quot;</span><span style="color: #66cc66;">&#41;</span>,<span style="color: #ff0000;">&quot;.$1&quot;</span><span style="color: #66cc66;">&#41;</span>;
                <span style="color: #808080; font-style: italic;">// the string is from the beginning to the end</span>
                regexp = <span style="color: #ff0000;">&quot;^&quot;</span> + regexp + <span style="color: #ff0000;">&quot;$&quot;</span>;
                <span style="color: #808080; font-style: italic;">// return true is found</span>
                <span style="color: #b1b100;">return</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">string</span>.<span style="color: #006600;">search</span><span style="color: #66cc66;">&#40;</span>regexp<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&gt;</span>= <span style="color: #cc66cc;">0</span> ? <span style="color: #000000; font-weight: bold;">true</span> : <span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">&#41;</span>;
            <span style="color: #66cc66;">&#125;</span>
&nbsp;
            <span style="color: #808080; font-style: italic;">// initialization</span>
            <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
            <span style="color: #66cc66;">&#123;</span>
                <span style="color: #808080; font-style: italic;">// data grid initialization</span>
                dataGridData = dataGridStartData.<span style="color: #006600;">children</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
            <span style="color: #66cc66;">&#125;</span>
        <span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&gt;</span>
    <span style="color: #66cc66;">&lt;/</span>mx:Script<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;/</span>mx:Application<span style="color: #66cc66;">&gt;</span></pre></td></tr></table></div>

<p>The important function is <strong>matchWildcards</strong> which takes two parameters: the first one is the string to search into and the second one is the search term or the filtering string. The function return true or false depending if the two strings matches or not.</p>
<p>As explained in the code in the <strong>matchWildcards</strong> the following step are taken:</p>
<ol>
<li>escape special regexp characters</li>
<li>transform wildcards to regexp: <br /><strong>&#8220;*&#8221;</strong> into <strong>&#8220;.*&#8221;</strong> <br /><strong>&#8220;?&#8221;</strong> into <strong>&#8220;.?&#8221;</strong><br /><em>(exclude commas)</em></li>
<li>add beginning and end regexp constraints: <strong>&#8220;^&#8221;</strong> and <strong>&#8220;$&#8221;</strong> <em>(exclude commas)</em></li>
<li>search it and return the result</li>
</ol>
<p>This is it. Hope this will be helpful.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flexer.info/2008/08/08/how-to-create-a-wildcard-filename-search/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>How To Escape All Regexp Special Chars</title>
		<link>http://www.flexer.info/2008/08/07/how-to-escape-all-regexp-special-chars/</link>
		<comments>http://www.flexer.info/2008/08/07/how-to-escape-all-regexp-special-chars/#comments</comments>
		<pubDate>Thu, 07 Aug 2008 16:06:50 +0000</pubDate>
		<dc:creator>Andrei Ionescu</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[How to]]></category>
		<category><![CDATA[MXML]]></category>
		<category><![CDATA[Regexp]]></category>
		<category><![CDATA[regular expression]]></category>

		<guid isPermaLink="false">http://www.flexer.info/?p=237</guid>
		<description><![CDATA[This is a very helpful piece of code. Function to escape all regular expression special chars. I came to this string having this order of characters by trial and error. So now you can use it easily by copy and paste.
What is important to know that MXML and Actionscript compiler do automatically escapes backslashes (&#8220;\&#8221;) [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-right: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.flexer.info%2F2008%2F08%2F07%2Fhow-to-escape-all-regexp-special-chars%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.flexer.info%2F2008%2F08%2F07%2Fhow-to-escape-all-regexp-special-chars%2F" height="61" width="51" /></a></div><div style="float: right; margin-right: 10px"><a class="google_buzz"  
href="http://www.google.com/reader/link?url=http://www.flexer.info/2008/08/07/how-to-escape-all-regexp-special-chars/&title=How+To+Escape+All+Regexp+Special+Chars&srcURL=http://www.flexer.info" target="_blank" rel="nofollow"><img
src="http://www.flexer.info/wp-content/plugins/google-buzz-button-for-wordpress/images/google-buzz.png" alt="Google Buzz" /></a></div><p>This is a very helpful piece of code. Function to escape all regular expression special chars. I came to this string having this order of characters by trial and error. So now you can use it easily by copy and paste.</p>
<p>What is important to know that MXML and Actionscript compiler do automatically escapes backslashes (&#8220;\&#8221;) and because of this you may encounter a lot of problems with regular expression.</p>
<p>This piece of code makes use a lot of regular expression so to fully understand the expression you really need to get into regular expression &#8220;language&#8221;.</p>
<p>So here it is&#8230;<br />

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_escape_all_specials_921625011"
			class="flashmovie"
			width="400"
			height="200">
	<param name="movie" value="/wp-content/uploads/2008/08/escape_all_specials.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="/wp-content/uploads/2008/08/escape_all_specials.swf"
			name="fm_escape_all_specials_921625011"
			width="400"
			height="200">
	<!--<![endif]-->
		
	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object><br />
&nbsp;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>?<span style="color: #0066CC;">xml</span> <span style="color: #0066CC;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;</span>mx:Application xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> 
    layout=<span style="color: #ff0000;">&quot;absolute&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;400&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;200&quot;</span><span style="color: #66cc66;">&gt;</span>
    <span style="color: #66cc66;">&lt;</span>mx:TextArea id=<span style="color: #ff0000;">&quot;oldstr&quot;</span> <span style="color: #0066CC;">text</span>=<span style="color: #ff0000;">&quot;{}()^$&amp;amp;.*?-/+|[]<span style="color: #000099; font-weight: bold;">\&quot;</span> 
        x=&quot;</span><span style="color: #cc66cc;">10</span><span style="color: #ff0000;">&quot; y=&quot;</span><span style="color: #cc66cc;">10</span><span style="color: #ff0000;">&quot; width=&quot;</span><span style="color: #cc66cc;">380</span><span style="color: #ff0000;">&quot; height=&quot;</span><span style="color: #cc66cc;">70</span><span style="color: #ff0000;">&quot;/&gt;
    &lt;mx:TextArea id=&quot;</span>newstr<span style="color: #ff0000;">&quot; x=&quot;</span><span style="color: #cc66cc;">10</span><span style="color: #ff0000;">&quot; y=&quot;</span><span style="color: #cc66cc;">118</span><span style="color: #ff0000;">&quot; width=&quot;</span><span style="color: #cc66cc;">380</span><span style="color: #ff0000;">&quot; height=&quot;</span><span style="color: #cc66cc;">70</span><span style="color: #ff0000;">&quot;/&gt;
    &lt;mx:Button x=&quot;</span><span style="color: #cc66cc;">149</span><span style="color: #ff0000;">&quot; y=&quot;</span><span style="color: #cc66cc;">88</span><span style="color: #ff0000;">&quot; label=&quot;</span>Escape <span style="color: #0066CC;">string</span><span style="color: #ff0000;">&quot; 
        click=&quot;</span>handleDoEscape<span style="color: #66cc66;">&#40;</span>event<span style="color: #66cc66;">&#41;</span><span style="color: #ff0000;">&quot;/&gt;
    &lt;mx:Script&gt;
        &lt;![CDATA[
            // string to test with: {}()^$&amp;.*?-/+|[]<span style="color: #000099; font-weight: bold;">\</span>
            private function escapeRegexChars(s:String):String
            {
                var newString:String = 
                    s.replace(
                        new RegExp(&quot;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span>\<span style="color: #66cc66;">&#40;</span>\<span style="color: #66cc66;">&#41;</span>\^$<span style="color: #66cc66;">&amp;</span>.\<span style="color: #66cc66;">*</span>\?\<span style="color: #66cc66;">/</span>\+\<span style="color: #66cc66;">|</span>\<span style="color: #66cc66;">&#91;</span>\\\\<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">|</span>\<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">|</span>\-<span style="color: #66cc66;">&#41;</span><span style="color: #ff0000;">&quot;,&quot;</span>g<span style="color: #ff0000;">&quot;),
                        &quot;</span>\\$<span style="color: #cc66cc;">1</span><span style="color: #ff0000;">&quot;);
                return newString;
            }
&nbsp;
            private function handleDoEscape(event:Event):void
            {
                newstr.text = escapeRegexChars(oldstr.text);
            }
        ]]&gt;
    &lt;/mx:Script&gt;
&lt;/mx:Application&gt;</span></pre></td></tr></table></div>

<p>Easy codding&#8230; and learn Regexp!</p>
<p>Useful site for learning and more: <a href="http://www.regular-expressions.info/" target="_blank">http://www.regular-expressions.info/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flexer.info/2008/08/07/how-to-escape-all-regexp-special-chars/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

