THIS IS NOT COMPLETE
Table of Contents [hide]
Mythryl has two pages of note on regular expressions:
- https://mythryl.org/my-Regular_Expressions.html
-
https://mythryl.org/my-More_Regular_Expressions.html#section:tut:full-monte:regex
A trivial regular expression ∞
A basic regular expression match can be done with =~
like so:
if ( "hello" =~ "h" ) printf "matched"; else printf "no match"; fi; # => # matched
if ( "hello" =~ "a" ) printf "matched"; else printf "no match"; fi; # => # no match
More complex regular expressions ∞
Here is what Mythryl's Regular Expression Matcher documentation has for find_first_match_to_regex
:
find_first_match_to_regex : String -> String -> Null_Or(String );
An example:
fun silent_regex_find_first_group( rx:String, string:String ): String = { case( regex::find_first_match_to_ith_group 1 rx string ) THE x => x; NULL => ""; esac; }; printf "%s" ( silent_regex_find_first_group( "(match|smash)", "match this string" ) ); # => # match
More complex things can be done:
fun silent_regex_find_first_group( rx:String, string:String ): String = { case( regex::find_first_match_to_ith_group 1 rx string ) THE x => { printf "I did find something\n"; x; }; NULL => { printf "I didn't find anything\n"; ""; }; esac; }; printf "%s" ( silent_regex_find_first_group( "(match|smash)", "match this string" ) ); # => # I did find something # match
Other methods ∞
There were some ugly Mythryl 6.0.0 ways to deal with regular expressions. These seem to be obsolete as of 7.1.0 . View the source of this page to see those old notes, in a rather ugly form.
Last updated 2019-12-06 at 11:22:23