Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejavascript
themeConfluence
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
linenumberstrue
"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:

...

The sprintf() operator can be applied to either a number or a string. The operator takes a formatting string as its sole argument. Use \%s to escape a literal %s and \\ to escape a literal \:

Code Block
languagejavascript
themeConfluence
a = "Hello world!"
b = a.sprintf("<%s \%s>") // b = "<Hello world! %s>"

...

The substr() operator returns a substring of the target string. The operator takes an argument that gives an offset from the start of the string to begin returning the substring and an optional length that gives the desired length of the substring. If the length is omitted, the substring to the end of the original string from the offset will be returned. If the length is negative, the length will be caluclated calculated from the end of the string. For example:

...