4 amelie := "Am\{UE9}lie"
5 amelie2 := "Am\{U65}\{U301}lie"
6 >> $Pat"e".replace_in("Hello", "X")
9 >> $Pat"l".is_in("Hello")
11 >> $Pat"l{end}".is_in("Hello")
13 >> $Pat"{start}l".is_in("Hello")
16 >> $Pat"o".is_in("Hello")
18 >> $Pat"o{end}".is_in("Hello")
20 >> $Pat"{start}o".is_in("Hello")
23 >> $Pat"H".is_in("Hello")
25 >> $Pat"H{end}".is_in("Hello")
27 >> $Pat"{start}H".is_in("Hello")
30 >> $Pat"l".replace_in("Hello", "")
32 >> $Pat"x".replace_in("xxxx", "")
34 >> $Pat"y".replace_in("xxxx", "")
36 >> $Pat"e ".replace_in("One two three four five six", "")
37 = "Ontwo threfour fivsix"
39 >> $Pat"{start}{space}".replace_in(" one ", "")
41 >> $Pat"{space}{end}".replace_in(" one ", "")
44 >> amelie.has_pattern($Pat"$amelie2")
47 >> $Pat"{alpha}".replace_in("one two three", "")
49 >> $Pat"{alpha}".replace_in("one two three", "word")
52 say("Test splitting and joining text:")
54 >> "one two three".split_pattern($Pat" ")
55 = ["one", "two", "three"]
57 >> "one,two,three,".split_pattern($Pat",")
58 = ["one", "two", "three", ""]
60 >> "one two three".split_pattern($Pat"{space}")
61 = ["one", "two", "three"]
63 >> "abc".split_pattern($Pat"")
66 >> ", ".join(["one", "two", "three"])
69 >> "".join(["one", "two", "three"])
78 say("Test text.find_patterns()")
79 >> " #one #two #three ".find_patterns($Pat"#{alpha}")
80 = [PatternMatch(text="#one", index=2, captures=["one"]), PatternMatch(text="#two", index=8, captures=["two"]), PatternMatch(text="#three", index=13, captures=["three"])]
82 >> " #one #two #three ".find_patterns($Pat"#{!space}")
83 = [PatternMatch(text="#one", index=2, captures=["one"]), PatternMatch(text="#two", index=8, captures=["two"]), PatternMatch(text="#three", index=13, captures=["three"])]
85 >> " ".find_patterns($Pat"{alpha}")
88 >> " foo(baz(), 1) doop() ".find_patterns($Pat"{id}(?)")
89 = [PatternMatch(text="foo(baz(), 1)", index=2, captures=["foo", "baz(), 1"]), PatternMatch(text="doop()", index=17, captures=["doop", ""])]
91 >> "".find_patterns($Pat'')
94 >> "Hello".find_patterns($Pat'')
97 say("Test text slicing:")
100 >> "abcdef".slice(from=3)
102 >> "abcdef".slice(to=-2)
104 >> "abcdef".slice(from=2, to=4)
106 >> "abcdef".slice(from=5, to=1)
113 >> house.codepoint_names()
114 = ["CJK Unified Ideographs-5BB6"]
115 >> house.utf32_codepoints()
118 >> "🐧".codepoint_names()
121 >> Text.from_codepoint_names(["not a valid name here buddy"])
124 >> "one two; three four".find_patterns($Pat"; {..}")
125 = [PatternMatch(text="; three four", index=8, captures=["three four"])]
131 >> $Pat"{lower}".replace_in("Hello", "(@0)")
134 >> $Pat"foo(?)".replace_in(" foo(xyz) foo(yyy) foo(z()) ", "baz(@1)")
135 = " baz(xyz) baz(yyy) baz(z()) "
137 >> "<tag>".translate_patterns({$Pat"<"="<", $Pat">"=">"})
140 >> $Pat"BAD(?)", "good(@1)".replace_in(" BAD(x, fn(y), BAD(z), w) ", recursive=yes)
141 = " good(x, fn(y), good(z), w) "
143 >> $Pat"BAD(?)", "good(@1)".replace_in(" BAD(x, fn(y), BAD(z), w) ", recursive=no)
144 = " good(x, fn(y), BAD(z), w) "
146 >> "Hello".matches_pattern($Pat"{id}")
148 >> "Hello".matches_pattern($Pat"{lower}")
150 >> "Hello".matches_pattern($Pat"{upper}")
152 >> "Hello...".matches_pattern($Pat"{id}")
155 >> "hello world".map_pattern($Pat"world", func(m:PatternMatch) m.text.upper())
161 >> $Pat"{space}".trim(" abc def ")
163 >> $Pat"{!digit}".trim(" abc123def ")
165 >> $Pat"{!digit}".trim(" abc123def ", left=no)
167 >> $Pat"{!digit}".trim(" abc123def ", right=no)
169 # Only trim single whole matches that bookend the text:
170 >> $Pat"Abc".trim("AbcAbcxxxxxxxxAbcAbc")
173 >> $Pat"{..}={..}".replace_in("A=B=C=D", "1:(@1) 2:(@2)")