Module extensions.string

Extensions to the Lua standard string library.

Functions

startswith (str, pattern[, plain]) Returns whether or not the string starts with pattern.
endswith (str, pattern[, plain]) Returns whether or not the string ends with pattern.
patternescape (str) Returns a new string with all Lua Pattern special characters escaped.
trim (str, pattern) Returns a new string with all leading and trailing whitespace removed.
rjust (str, final_len[, pattern]) Returns a new string with the left padded with pattern or spaces until the string is final_len characters long.
cjust (str, final_len[, pattern]) Returns a new string with both sides padded with pattern or spaces until the string is final_len characters long.
ljust (str, final_len[, pattern]) Returns a new string with the right padded with pattern or spaces until the string is final_len characters long.
split (str[, delim[, plain]]) Returns a table of all elements of the string split on delim.
random (final_len[, mn[, mx]]) Returns a string of final_len random characters in the byte-range of [mn, mx].
levenshtein (str1, str2) Returns the Levenshtein distance between the two strings.
dameraulevenshtein (str1, str2) Returns the Damerau-Levenshtein distance between the two strings.
subsequencematch (subseq, str) Returns true if the subsequence can be found inside str.


Functions

startswith (str, pattern[, plain]) line 17
Returns whether or not the string starts with pattern. Use plain if you want to match pattern literally.

Parameters:

  • str string
  • pattern string
  • plain boolean (optional)

Returns:

    boolean
endswith (str, pattern[, plain]) line 27
Returns whether or not the string ends with pattern. Use plain if you want to match pattern literally.

Parameters:

  • str string
  • pattern string
  • plain boolean (optional)

Returns:

    boolean
patternescape (str) line 45
Returns a new string with all Lua Pattern special characters escaped.

Parameters:

  • str string

Returns:

    string
trim (str, pattern) line 54
Returns a new string with all leading and trailing whitespace removed. A pattern may be provided to instead strip using that pattern.

Parameters:

  • str string
  • pattern ? string

Returns:

    string
rjust (str, final_len[, pattern]) line 69
Returns a new string with the left padded with pattern or spaces until the string is final_len characters long.

Multi-byte padding will not overshoot final_len.

Parameters:

  • str string
  • final_len number
  • pattern string (optional)

Returns:

    string
cjust (str, final_len[, pattern]) line 82
Returns a new string with both sides padded with pattern or spaces until the string is final_len characters long.

Multi-byte padding will not overshoot final_len.

Parameters:

  • str string
  • final_len number
  • pattern string (optional)

Returns:

    string
ljust (str, final_len[, pattern]) line 96
Returns a new string with the right padded with pattern or spaces until the string is final_len characters long.

Multi-byte padding will not overshoot final_len.

Parameters:

  • str string
  • final_len number
  • pattern string (optional)

Returns:

    string
split (str[, delim[, plain]]) line 107
Returns a table of all elements of the string split on delim. Use plain if the delimiter provided is not a pattern.

Parameters:

  • str string
  • delim string (optional)
  • plain boolean (optional)

Returns:

    table
random (final_len[, mn[, mx]]) line 143
Returns a string of final_len random characters in the byte-range of [mn, mx]. By default mn = 0 and mx = 255.

Parameters:

  • final_len number
  • mn number (optional)
  • mx number (optional)

Returns:

    string
levenshtein (str1, str2) line 161
Returns the Levenshtein distance between the two strings. This is often referred as "edit distance". Wikipedia "Levenshtein Distance"

Parameters:

  • str1 string
  • str2 string

Returns:

    number
dameraulevenshtein (str1, str2) line 200
Returns the Damerau-Levenshtein distance between the two strings. This is often referred as "edit distance". Wikipedia "Damerau-Levenshtein Distance"

Parameters:

  • str1 string
  • str2 string

Returns:

    number
subsequencematch (subseq, str) line 243
Returns true if the subsequence can be found inside str. For example: ggl is a subsequence of GooGLe. (uppercase letters signify which letters form the subsequence).

Parameters:

  • subseq string
  • str string

Returns:

    boolean