? PATTERNTRAN("1st-title: ANAME-HER : 3520931 place[21-22]", "\[.*-.*\]",".","-") * A function to translate a pattern with a string * Arguments as main arguments in STRTRAN * A fourth optional argument allows to replace inside the match, only FUNCTION PATTERNTRAN (tcSearched AS String, tcPatternSought AS String, tcReplacement AS String, tcSoughtInMatch AS String) LOCAL lcTranslated AS String LOCAL lcTranslatedMatch AS String * load regular expression engine IF !"\_REGEXP.VCX" $ SET("Classlib") SET CLASSLIB TO (ADDBS(HOME(1)) + "ffc\_regexp.vcx") ADDITIVE ENDIF LOCAL loRegExpr AS _regexp m.loRegExpr = CREATEOBJECT("_regexp") m.loRegExpr.Pattern = m.tcPatternSought * check if there is a match IF m.loRegExpr.Execute(m.tcSearched,.F.) = 1 * if we want to replace inside the match, only IF PCOUNT() = 4 * perform a standard translation inside the match m.lcTranslatedMatch = STRTRAN(m.loRegExpr.Matches[1,2], m.tcSoughtInMatch, m.tcReplacement) * and then apply the translation to the match inside the original string m.lcTranslated = STRTRAN(m.tcSearched, m.loRegExpr.Matches[1,2], m.lcTranslatedMatch) ELSE * otherwise, just replace the match with the replacement m.lcTranslated = STRTRAN(m.tcSearched, m.loRegExpr.Matches[1,2], m.tcReplacement) ENDIF ELSE * with no pattern found, the string is returned unstranslated m.lcTranslated = m.tcSearched ENDIF RETURN m.lcTranslated ENDFUNC