The RegularExpressions Project

Team Fly 

Page 579

In the replacement string we'll make use of the two grouped subexpressions in the regular expression. The following replacement pattern will place each key and each value in square brackets and each pair on a separate line:

 [$1] : [$2] 

You must also press the Enter key once at the end of the replacement string. If not, each key/value pair won't be printed on a separate line. You must also make sure that there's no newline character at the end of the search pattern. The text after replacing all instances of the search pattern with the replacement string is shown next. The text contains the same data as the original document, but it appears in a nicer format (see Figure 19.7):

 [value1] : [34] [value2] : [405] [value3] : [4534] [value4] : [45] [value5] : [3334] [value10] : [-4554] [value11] : [3904] [value12] : [456] [value13] : [5564] 

image

FIGURE 19.7 Cleaning a data file with a regular expression that captures all the instances of the same pattern in the text

The RegularExpressions Project

Now we can examine the code of the RegularExpressions project, which you can use to experiment with regular expressions, or process long text files using regular expressions. In the Search Pattern box you enter a regular expression that determines the matches you want to locate in the text, which is entered in the Text box (just copy the text you want to search and paste it in the Text box). Then you can click the Find First Match and Find Next Match buttons to locate the matches in the text.

Team Fly 


Visual Basic  .NET Power Tools
Visual Basic .NET Power Tools
ISBN: 0782142427
EAN: 2147483647
Year: 2003
Pages: 178

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net