~ multimethod
Methods
- ~(something:Any, pred:Any)deprecated Source: stdlib.ngs:870
EXPERIMENTAL! Do not use! Especially don't count on returned value beyond obvios Bool(x) behaviour. Match anything.
- ~(arr:Arr, r:PredRange) Source: stdlib.ngs:1978
Check whether the array contains the given range. Finds first match. Returns
MatchExample
a = %[a1 a2 b1 b2] m = a ~ /^a/../^b/ # Exclusive range # m.matches == [['a2']] # m.before == ['a1'] # m.after == ['b1', 'b2']
- ~(haystack:Str, needle:Str, offset:Int=0) Source: stdlib.ngs:3508
Find substring in string. Uses pos(). Returns
MatchExample
"abc" ~ "bc" # <MatchY ...> "abc" ~ "X" # <MatchN>
- ~(s:Str, pfx:Pfx) Source: stdlib.ngs:5357
Check whether s starts with pfx. Returns
MatchExample
"abcde" ~ Pfx("ab") # <MatchY matches=['ab'] before= after=cde> "abcde" ~ Pfx("xy") # <MatchN >
- ~(s:Str, i:Ifx) Source: stdlib.ngs:5364
Undocumented
- ~(s:Str, sfx:Sfx) Source: stdlib.ngs:5371
Check whether s ends with sfx. Returns
MatchExample
"abcde" ~ Sfx("de") # <MatchY matches=['de'] before=abc after=> "abcde" ~ Pfx("xy") # <MatchN >
- ~(s:Str, r:RegExp, offset:Int=0, options:Int=0) Source: stdlib.ngs:5401
Find PCRE regular expression in s. Empty string without options returns MatchN. Throws Error if more than 20 captures are used or if there is an error during matching. Automatically called by NGS for syntax
my_str ~ my_regexp
Parameters
offset search start offset options options to pass to underlying PCRE_EXEC(3). Returns
MatchExample
globals().keys().filter(/^C_PCRE/) # lists possible options "xabcy" ~ /a(.)c/ # <MatchY matches=['abc','b'] named={} positions=[[1,4],[2,3]] whole=abc before=x after=y> m = ("xabcy" ~ /a(?P<mychar>.)c/) echo(m.named.mychar) # Outputs: b
- ~(argv:Arr, udm:UserDefinedMethod) Source: autoload/ArgvMatcher.ngs:51
Please do not use directly! Tries to match command line arguments with closure parameters. Parameters
argv Command line arguments, typically ARGV udm UserDefinedMethod to match with Returns
Match (ParamsMatchY on success, ParamsMatchN on failure). If ParamsMatchY is returned it has "matches" field with values in suitable order to call c. If ParamsMatchN is returned, it has "message" field explaining why there was no match. Currently it's not printed anywhere.Example
ArgvMatcher; (["--b", "B", "A", "C"] ~ F(a,b,c) 7).matches # %[A B C] (["A", "C", "D", "--b", "B"] ~ ArgvMatcher("positionals", "a") do F(a,b) 7).matches # %[%[A C D] B]