Regex example
Example to play with regular expressions.
Compilation
Easiest way to get this example running is to go to examples directory in package root, and run:
$ ./build.sh regex_tests
build.sh script compiles Ano script to C, copies source files in place and pops up instructions what to do next. Follow them. Check also examples/README for more info.
Preview
; ------------------------------------------------------------------------------
; regex_tests.ano
;
; To compile:
;
; $ ./build/ano ./examples/regex_tests/regex_tests.ano > \
; engine/dsl_ano.h
; ------------------------------------------------------------------------------
;
; @ANO_SCRIPT_NAME regex_tests
; @ANO_SCRIPT_VERSION 0.0.1
; @ANO_SCRIPT_DESCRIPTION Simple regex example
;
; @ANO_FLAGS_USE_PROTOS [ ]
; @ANO_FLAGS_VAR_NAME_SUBS [ ]
; @ANO_FLAGS_VAR_WARN_UNUSED [ ]
;
; Copyright © 2016-2026, Jani Salonen <salojan@goto10.co>
; All rights reserved.
;
; Example to play with regular expressions.
;
main [exit: 0] {
mov _string ("Hello, world!")
; Test match…
;
regex_test (\
pattern: "World", \
string: _string, \
flags: "")
print "Test returned " . rc . " when testing '" . _string . \
"' with string 'World'\nusing case sensitive match.\n"
; …and other way round.
;
regex_test (\
pattern: "World", \
string: _string, \
flags: "i")
print "Test returned " . rc . " when testing '" . _string . \
"' with string 'World'\nusing case insensitive match.\n"
; Get matched substring.
;
regex_match (\
pattern: "world", \
string: _string, \
flags: "i")
print "Match returned '" . rc . "' matching '" . _string . \
"' with string 'world'\nusing case insensitive match.\n"
; Replace one occurrence.
;
regex_subs (\
pattern: "world", \
string: _string, \
replace: "Finland", \
flags: "")
print "Substitution returned '" . rc . "' matching '" . _string . \
"'\nreplacing string 'world' with 'Finland' using case" \
" sensitive match.\n"
; Global replace.
;
regex_subs (\
pattern: "l", \
string: _string, \
replace: "x", \
flags: "gi")
print "Substitution returned '" . rc . "' matching '" . _string . \
"'\nreplacing character 'l' with 'x' using case sensitive" \
" global match.\n"
}
; ------------------------------------------------------------------------------ ; regex_tests.w2c ; ; To compile: ; ; $ ./build/widget ./examples/regex_tests/regex_tests.w2c > \ ; engine/widget_defs.h ; ------------------------------------------------------------------------------
; ------------------------------------------------------------------------------ ; regex_tests.m2c ; ; To compile: ; ; $ ./build/menu ./examples/regex_tests/regex_tests.m2c > \ ; engine/menu_defs.h ; ------------------------------------------------------------------------------
Copyright © 2026, Jani Salonen <salojan at goto10 piste co>. Piste is finnish word and means dot. All rights reserved.