Article Preview
Buy Now
FEATURE
Expressions of Delight
REALbasic's Regex class
Issue: 1.1 (August/September 2002)
Author: Matt Neuburg
Author Bio: Matt Neuburg first learned about regular expressions while using the Nisus word processor in 1990, and hasn't had a good night's sleep since.
Article Description: How to use regular expressions in REALbasic
Article Length (in bytes): 23,888
Starting Page Number: 24
Article Number: 1005
Resource File(s):
1005.zip Updated: 2013-03-11 19:07:55
Related Link(s): None
Excerpt of article text...
The Regex class, along with the RegexMatch, RegexOptions, and RegexException classes, is the gateway to REALbasic's implementation of regular expressions. Regular expressions are a way of expressing a textual find or find-and-replace that's too complicated, or too vague, for a function like InStr or Replace. To see what I mean, let's take an example.
Suppose you've got a string representing some HTML, and you want to remove all the HTML markup from it. An HTML tag starts with a left angle-bracket and ends with a right angle-bracket; the tag consists of both angle-brackets, and everything in between, like this: "<TAG>". The trouble is, of course, that you don't know in advance what "everything in between" consists of.
So how would you find and remove an HTML tag using just InStr? You'd have to take a piecemeal approach. First you'd have to find a left angle-bracket, and remember where it is. Then you'd look for a right angle-bracket that comes after the left angle-bracket, and remember where it is. Then you'd have to break up the string into three pieces & what precedes the tag, the tag itself, and what follows the tag & and reassemble it without the middle piece, thus deleting the tag. Here's some actual code.
Manual removal of HTML tag:
dim s, leftPart, rightPart as string
...End of Excerpt. Please purchase the magazine to read the full article.