1 The `match()` function applies the given regular expression pattern on 2 the given subject value. 3 4 Depending on whether the given regular expression sets the global (`g`) 5 modifier, either an array of match groups or the first match group is 6 returned. 7 8 Returns `null` if the given pattern argument is not a regular expression 9 value, or if the subject is `null` or unspecified. 10 11 -- Testcase -- 12 {% 13 print(join("\n", [ 14 // match all key=value pairs 15 match("kind=fruit name=strawberry color=red", /([[:alpha:]]+)=([^= ]+)/g), 16 17 // match any word 18 match("The quick brown fox jumps over the lazy dog", /[[:alpha:]]+/g), 19 20 // match the first three lowercase words 21 match("The quick brown fox jumps over the lazy dog", / ([[:lower:]]+) ([[:lower:]]+) ([[:lower:]]+)/), 22 23 // special case: match any empty string sequence 24 match("foo", /()/g), 25 26 // special case: match first empty string sequence 27 match("foo", /()/), 28 29 // subject is implictly converted to string 30 match(true, /u/) 31 ]), "\n"); 32 %} 33 -- End -- 34 35 -- Expect stdout -- 36 [ [ "kind=fruit", "kind", "fruit" ], [ "name=strawberry", "name", "strawberry" ], [ "color=red", "color", "red" ] ] 37 [ [ "The" ], [ "quick" ], [ "brown" ], [ "fox" ], [ "jumps" ], [ "over" ], [ "the" ], [ "lazy" ], [ "dog" ] ] 38 [ " quick brown fox", "quick", "brown", "fox" ] 39 [ [ "", "" ], [ "", "" ], [ "", "" ], [ "", "" ] ] 40 [ "", "" ] 41 [ "u" ] 42 -- End -- 43 44 45 Omitting the subject yields `null`. 46 47 -- Testcase -- 48 {% 49 printf("%.J\n", match(null, /u/)); 50 %} 51 -- End -- 52 53 -- Expect stdout -- 54 null 55 -- End --
This page was automatically generated by LXR 0.3.1. • OpenWrt