(!****************************************************** Mosel User Guide Example Problems ================================= file regex.mos `````````````` Regular expression matching and replacement. (c) 2015 Fair Isaac Corporation author: S. Heipcke, Apr 2015 *******************************************************!) model "test regex" uses "mmsystem" declarations m: array(0..3) of textarea ! m(0) whole identified zone, m(1) [,...,m(9)] match results t: text end-declarations !**** Pattern matching **** t:="MyValue=10,Sometext mytext MoretextMytext2, MYVAL=1,5 mYtext3" ! Display all strings starting with 'My' (case insensitive) m(0).succ:=1 while (regmatch(t, '\0 then writeln(numr, " replacements: ", t) end-if ! The same using BRE syntax: t:="date1=20/11/2010,date2=1-Oct-2013,date3=2014-6-30" writeln( regreplace(t, '\(\d\{4\}\)-\([01]\{0,1\}\d\)-\([0-3]\{0,1\}\d\)', '\3/\2/\1' ), " replacements: ", t) ! The same more readable (ERE syntax): numr:= regreplace(t, '(\d{4})-([01]{0,1}\d)-([0-3]{0,1}\d)', '\3/\2/\1', 1, REG_EXTENDED ) (! \d or [:digit:] numerical character ? 0 times or once (ERE only) {M,N} minimum M and maximum N match count [] set of possible character matches !) end-model