Add notes on Space Lua Pattern Matching (#1366)
This commit is contained in:
@@ -12,7 +12,7 @@ import printf from "./printf.ts";
|
||||
const ROSETTA_STONE = {
|
||||
"([^a-zA-Z0-9%(])-": "$1*?",
|
||||
"([^%])-([^a-zA-Z0-9?])": "$1*?$2",
|
||||
"(.)-$": "$1*?",
|
||||
"([^%])-$": "$1*?",
|
||||
"%a": "[a-zA-Z]",
|
||||
"%A": "[^a-zA-Z]",
|
||||
"%c": "[\x00-\x1f]",
|
||||
|
||||
@@ -155,10 +155,13 @@ assertEqual(string.match("abc123", "%a+"), "abc")
|
||||
assertEqual(string.match(" abc", "%s+"), " ")
|
||||
|
||||
-- Test multiple captures
|
||||
local day, month, year = string.match("2024-03-14", "(%d+)%-(%d+)%-(%d+)")
|
||||
assertEqual(day, "2024")
|
||||
local year, month, day = string.match("2024-03-14", "(%d+)%-(%d+)%-(%d+)")
|
||||
assertEqual(year, "2024")
|
||||
assertEqual(month, "03")
|
||||
assertEqual(year, "14")
|
||||
assertEqual(day, "14")
|
||||
|
||||
-- Test escaped hyphen at the end of a pattern
|
||||
assertEqual(string.match("4-", "%d%-"), "4-")
|
||||
|
||||
-- Test optional captures
|
||||
local word = string.match("The quick brown fox", "%s*(%w+)%s*")
|
||||
|
||||
Reference in New Issue
Block a user