In order to test the regular expression in the development process is more convenient, using Flex to write the following regular expression testing tools, but also share, welcome suggestions for improvement
View in a separate window: http://my.jhost.cn/iihe602_2/flex/sdk3/RegexTester.html
Now the sample is less, will gradually increase in the future
1 <?xml version= "1.0" encoding= "Utf-8"?>
2 <mx:application xmlns:mx= "Http://www.adobe.com/2006/mxml" layout= "vertical" horizontalalign= "left"
3 backgroundcolor= "white" fontsize= "creationcomplete=" Requestexampleshandler () >
4
5 <mx:array id= "Options" >
6 <mx:object label= "All matches" data= "G"/>
7 <mx:object label= "Ignore case" data= "I"/>
8 <mx:object label= "Match multiple Lines" data= "M"/>
9 <mx:object label= "matching line breaks" data= "x"/>
<mx:object label= "Allow extended-point expressions" data= "E"/>
</mx:Array>
12
<mx:applicationcontrolbar dock= "true" >
<mx:label text= "option:"/>
<mx:repeater id= "Repeateroptions" dataprovider= "{options}" >
<mx:checkbox id= "Checkboxoption" label= "{RepeaterOptions.currentItem.label}"
Selected= "true" click= "Optionclick (event)"/>
</mx:Repeater>
</mx:ApplicationControlBar>
20
<mx:hdividedbox width= "100%" height= "100%" >
<mx:dividedbox width= "70%" height= "100%" >
23
<mx:vbox width= "100%" height= "15%" minheight= ">"
<mx:HBox>
<mx:label text= "pattern:"/>
<mx:spacer width= "100%"/>
<mx:button label= "Match" click= "Matchhandler (event)"/>
<mx:button label= "Execute" click= "Executehandler (event)"/>
</mx:HBox>
31
<mx:textarea id= "Textpattern" width= "100%" height= "100%"/>
</mx:VBox>
34
<mx:vbox width= "100%" height= "15%" minheight= ">"
<mx:HBox>
Notoginseng <mx:label text= "Replace with:"/>
<mx:button label= "Replace" click= "Replacehandler (event)"/>
</mx:HBox>
<mx:textarea id= "Textreplacewith" width= "100%" height= "100%"/>
</mx:VBox>
42
<mx:vbox width= "100%" height= "20%" minheight= ">"
<mx:label text= "Search text:"/>
<mx:textarea id= "Textsearch" width= "100%" height= "100%"/>
</mx:VBox>
47
<mx:vbox width= "100%" height= "50%" minheight= ">"
<mx:label text= "Result:"/>
<mx:textarea id= "Textresult" width= "100%" height= "100%"/>
Wuyi </mx:VBox>
52
</mx:DividedBox>
54
<mx:vbox width= "30%" height= "100%" >
<mx:label text= "Examples:"/>
<mx:list id= "Dataexamples" dataprovider= "[1,2,3]" width= "100%" height= "100%"
labelfield= "title" itemclick= "Itemclickhandler (event)"/>
</mx:VBox>
60
</mx:HDividedBox>
62
<mx:httpservice id= "Hsexamples" url= "Assets/examples.xml" resultformat= "e4x"
result= "Resulthandler (event)"/>
65
<mx:Script>
<! [cdata[
Import Mx.controls.Alert;
The import mx.rpc.events.ResultEvent;
70
The private var patteroptions:string = "Gimex";
72
Private Function Optionclick (event:mouseevent): void
74 {
Patteroptions = "";
A for (var i:uint = 0; i < checkboxoption.length; i++)
77 {
The IF (checkboxoption[i].selected)
Patteroptions + = Options[i].data;
80}
Bayi Trace (patteroptions);
82}
83
The Private Function Matchhandler (event:mouseevent): void
85 {
The var pattern:regexp = new RegExp (Textpattern.text, patteroptions);
var search:string = Textsearch.text;
The var Results:array = Search.match (pattern);
89
Textresult.text = Results.join ("\ n");
91}
92
The Private Function Executehandler (event:mouseevent): void
94 {
The var pattern:regexp = new RegExp (Textpattern.text, patteroptions);
The var search:string = Textsearch.text;
97
The var Result:array = pattern.exec (search);
Textresult.text = "";
var i:uint = 1;
The var lastindex:uint = Pattern.lastindex;
102 while (Result!= null)
103 {
Textresult.text + = "Matching:" + i++.tostring ();
(var prop:string in result)
106 {
Textresult.text + + "\n\t" + prop + ": T" + result[prop];
108}
109 Textresult.text + = "\---------------------------------------------------------\ n";
110//If the lastindex is always 0 if it is not global, it will cause an infinite loop, so you can only perform 1 times
Mr if (Pattern.lastindex = 0)
112 break;
113
114 result = pattern.exec (search);
115//two times after matching lastindex equal, indicating a dead loop, should exit
116 if (Pattern.lastindex = = lastindex)
117 break;
118
119 lastindex = Pattern.lastindex;
120}
121
122}
123
124 Private Function Replacehandler (event:mouseevent): void
125 {
126 var pattern:regexp = new RegExp (Textpattern.text, patteroptions);
127 var replacewith:string = Textreplacewith.text;
128 var search:string = Textsearch.text;
129 Textresult.text = Search.replace (pattern, replacewith);
130}
131
132 Private Function Requestexampleshandler (): void
133 {
134 Hsexamples.send ();
135}
136
137 Private Function Resulthandler (event:resultevent): void
138 {
139 Dataexamples.dataprovider = Event.result.item;
140}
141
The Private Function Itemclickhandler (event:event): void
143 {
144 var item:object = Event.target.selectedItem;
145 textpattern.text = Item.pattern;
146 Textreplacewith.text = Item.replace;
147 Textsearch.text = Item.search;
148}
149]]>
</mx:Script>
151
152 </mx:Application>
153
154