Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual page 307

Programming actionscript 3.0
Table of Contents

Advertisement

The
and
symbols the regular expression match the beginning and end of a line. The
^
$
(
) flag in the regular expression causes the regular expression to match the ^
multiline
symbol against the start of a line, not simply the start of the string.
The
method replaces all matching substrings (empty lines) with an empty string
replace()
(
). The
(
) flag in the regular expression ensures that the
""
g
global
replaces all matches in the string (not simply the first one).
Converting URLs to HTML <a> tags
When the user clicks the Test button in the sample application, if the user selected the
check box, the application calls the
urlToATag
convert URL strings from the input Wiki string into HTML
var protocol:String = "((?:http|ftp)://)";
var urlPart:String = "([a-z0-9_-]+\.[a-z0-9_-]+)";
var optionalUrlPart:String = "(\.[a-z0-9_-]*)";
var urlPattern:RegExp = new RegExp(protocol + urlPart + optionalUrlPart,
var result:String = input.replace(urlPattern,
"<a href='$1$2$3'><u>$1$2$3</u></a>");
The
constructor function is used to assemble a regular expression (
RegExp()
from a number of constituent parts. These constituent parts are each strings that define part
of the regular expression pattern.
The first part of the regular expression pattern, defined by the
URL protocol: either
indicated by the
symbol. This means that the parentheses are simply used to define a group
?
for the
alternation pattern; the group will not match backreference codes (
|
replacement string of the
The other constituent parts of the regular expression each use capturing groups (indicated by
parentheses in the pattern), which are then used in the backreference codes (
replacement string of the
The part of the pattern defined by the
characters:
,
,
a-z
0-9
The
indicates a required dot (
\.
least one of these characters:
The part of the pattern defined by the
following: a dot (
) character followed by any number of alphanumeric characters (including
.
and
). The
quantifier indicates that zero or more characters are matched.
_
-
*
"ig");
or
http://
ftp://
method.
replace()
method.
replace()
urlPart
, or
. The
quantifier indicates that at least one character is matched.
_
-
+
) character. And the remainder matches another string of at
.
,
,
, or
a-z
0-9
_
optionalUrlPart
URLParser.urlToATag()
<a>
protocol
. The parentheses define a noncapturing group,
string matches at least one of the following
.
-
string matches zero or more of the
method
replace()
static method to
tags.
urlPattern
string, defines an
,
,
) in the
$1
$2
$3
,
,
) in the
$1
$2
$3
Example: A Wiki parser
m
)
307

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 and is the answer not in the manual?

Questions and answers

This manual is also suitable for:

Flex

Table of Contents