Regular expressions: Difference between revisions

no edit summary
No edit summary
Line 520:
</lang>
 
=={{header|GeneXus}}==
Interesting link: http://wiki.gxtechnical.com/commwiki/servlet/hwiki?Regular+Expressions+%28RegEx%29,<br />
<br />
Replacement:<br />
<lang genexus>&string = &string.ReplaceRegEx("^\s+|\s+$", "") // it's a trim!
&string = &string.ReplaceRegEx("Another (Match)", "Replacing $1") // Using replace groups</lang>
Check match:
<lang genexus>If (&string.IsMatch("regex$"))
// The string ends with "regex"
EndIf</lang>
Split RegEx:
<lang genexus>&stringCollection = &string.SplitRegEx("^\d{2,4}")</lang>
Matches:
<lang genexus>&RegExMatchCollection = &string.Matches("(pa)tt(ern)")
For &RegExMatch In &RegExMatchCollection
&FullMatch = &RegExMatch.Value // &FullMatch contains the full pattern match: "pattern"
For &matchVarchar In &RegExMatch.Groups
// &matchVarchar contains group matches: "pa", "ern"
EndFor
EndFor</lang>
Flags: <br />
s - Dot matches all (including newline) <br />
m - multiline <br />
i - ignore case <br />
Using Flags Sintax: (?flags)pattern <br />
Example:<br />
<lang genexus>&string = &string.ReplaceRegEx("(?si)IgnoreCase.+$", "") // Flags s and i</lang>
Error Handling:
<lang genexus>&string = "abc"
&RegExMatchCollection = &string.Matches("[z-a]") // invalid pattern: z-a
&errCode = RegEx.GetLastErrCode() // returns 0 if no error and 1 if an error has occured
&errDsc = RegEx.GetLastErrDescription()</lang>
=={{header|Go}}==
<lang go>package main
Anonymous user