...
Code Block | ||||
---|---|---|---|---|
| ||||
e = my_url.extract(re#^http://(\[A-Za-z0-9.-\]+)/#); // e = [ "www.amazon.com" ] |
As of version 0.45.5, the second argument to the replace()
operator can be a function. When a match is found, this function will be called to determine the replacement string. It will be given, as its arguments, the string that matched, the capture groups in order, the index of the start of the match in the overall string (upon which replace
is operating), and finally the overall string itself. For example:
Code Block |
---|
"one 1 two 2 three 3".replace(re#([a-z]+) ([0-9])#g, match_function) |
Because the regular expression has the global flag (g
), the expression will match in three places and the match_function
will be called three times. The arguments for each of the three calls are shown here:
Code Block | ||
---|---|---|
| ||
"one 1", "one", "1", 0, "one 1 two 2 three 3"
"two 2", "two", "2", 6, "one 1 two 2 three 3"
"three 3", "three", "3", 12, "one 1 two 2 three 3" |
split()
The split()
operator takes a regular expression as its sole argument. The regular expression is used to split the original string into an array. For example:
...