The second list is the text that matches backreference 1, and so on. Regex Match(source, pattern, |, ). Unlike ...
ww449078
RegexMatch
RegexMatch()returnsanemptylistwithzeroelementsifthematchfails.Ifthematchsucceeds,thefirstlististhetextoftheentirematch(backreference0).Thesecondlististhetextthatmatchesbackreference1,andsoon.
RegexMatch(source,pattern,|,)
UnlikeRegex(),RegexMatch()iscaseinsensitive.IncludeMATCHCASEforacase-sensitivematch.IncludeNULLifyouwanttomatchcasebutthereisnoreplacementtext.
ExampleofParsingName-ValuePairs
Thefollowingexampleparsespairsofnamesandvalues.
RegexMatch(
"person=Fredid=77friend=favorite=tea",
"(\w+)=(\S*)(\w+)=(\S*)(\w+)=(\S*)(\w+)=(\S*)"
);
{"person=Fredid=77friend=favorite=tea","person","Fred","id","77","friend","","favorite","tea"}
The\w+matchesoneormorewordcharacters.The\S*matcheszeroormorecharactersthatarenotspaces.IntheresultingJSLlist,thefieldnames(person,id,friend,favorite)andtheircorrespondingvalues(Fred,77,"",tea)areseparatestrings.
IfthefirstargumenttoRegexMatch()isavariableandathirdargumentspecifiesthereplacementvalue,thematchedtextisreplacedinthevariable.
ComparingRegexandRegexMatch
Regex()andRegexMatch()matchapatterninagivenstringbutreturndifferentresults.Totransformsyourstringintoanotherstring,useRegex().Toidentifythesubstringsthatmatchspecificpartsofthepattern,useRegexMatch().
ThisexampleshowstheefficiencyofRegexMatch()comparedtoRegex().Thesourceisalistofsixstrings.Thegoalistoextractportionsofthosesixstringsintothesubject,verb,andobjectcolumnsofadatatable.
FinalDataTable source={"thecatatethechicken","thedogchasedthecat","didralphlikemary","thegirlpetsthedog","thesewordsarestrange","thecatwaschasedbythedog"};dt=NewTable("English101",//createthedatatable NewColumn("subject",character), NewColumn("verb",character), NewColumn("object",character));//iteratethroughthestringsinthelistFor(i=1,i<=NItems(source),i++, //assigntheresultofeachmatchtomatchList matchList=RegexMatch( source[i], /*scaneachstring,matchzeroormorecharacters andoneitemineachgroup*/ ".*?(cat|dog|ralph|girl).*?(ate|chased|like|pets).*?(chicken|cat|mary|dog)" );/*IfmatchListhaszeroitems(string5),don’taddarowtothetable.Puteachmatchedstringinseparatedatatablecells.*/ If(NItems(matchList)>0, dt<