In the process of building my own Flex-based chat application, I’m creating tidbits of code for testing purposes. In this particular case, I wanted a small app to test regex (regular expression) capabilities. There are numerous online regex search applications, yet they’re mostly written for PHP and Perl and I wasn’t quite sure if Flash handled them the same way.

This small app can be used online to test Flash’s regex search capabilities. I’ll likely post a similar article on the replace function, as it’s equally handy in my own developments.

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
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
	layout="absolute" width="100%" height="100%"
	creationComplete="textSearch()" viewSourceURL="srcview/index.html">
 
	<mx:Style>
		TextArea
		{
			cornerRadius: 5;
		}
		Application
		{
			backgroundColor: #FFFFFF;
		}
	</mx:Style>
 
	<mx:Script>
		<![CDATA[
 
			public function textSearch():void
			{
				searchResult.text = textToSearch.text.search(searchPattern.text).toString();
			}
 
		]]>
	</mx:Script>
 
	<mx:Form x="0" y="0" width="100%" height="100%">
		<mx:FormHeading label="Flex Regex Search"/>
		<mx:FormItem label="Text to search">
			<mx:TextArea id="textToSearch" text="Hello world!" change="textSearch()"/>
		</mx:FormItem>
		<mx:FormItem label="Search pattern">
			<mx:TextArea id="searchPattern" text="world!" change="textSearch()"/>
		</mx:FormItem>
		<mx:FormItem label="Search result">
			<mx:Text id="searchResult" text="Text"/>
		</mx:FormItem>
	</mx:Form>
 
</mx:Application>

Example: dm_regex_search.swf
Flex Project: dm_regex_search.zip

Leave a Reply