Regular expressions: Difference between revisions

(added Ol)
Line 1,091:
We can use named parameters (for Word) Try {Method Documents, "add", "", DocumentType:=WdNewWebPage as doc1}
 
New version using enumerator from object. Including a help SUB for displaying all functions of a COM object.
Enumerators for some COM objects are number of function -4&, we can use this in place of string for the name of property.
 
<lang M2000 Interpreter>
Line 1,113 ⟶ 1,115:
Print RegEx.Replace$("Myer Ken, Vice President, Sales and Services", " ")
pattern$="(\d{3})-(\d{3})-(\d{4})"
 
Method ObjRegEx, "Execute", "555-123-4567, 555-943-6717" as MyMatches
Print Type$(MyMatches) ' it is a IMatchCollection2
With MyMatches, "Count" as count, "Item" as List$()
For i=0 to Count-1 : Print List$(i) : Next i
 
 
Print RegEx.Replace$("555-123-4567, 555-943-6717", "($1) $2-$3")
Pattern$ = "(\S+), (\S+)"
Print RegEx.Replace$("Myer, Ken", "$2 $1")
Method ObjRegEx, "Execute", "Myer, Ken" as MyMatches
Rem : DisplayFunctions(MyMatches)
\\ we can use Enumerator
With MyMatches, "_NewEnum" as New Matches
Rem : DisplayFunctions(Matches)
With Matches, "Value" as New item$
While Matches {
Print Item$
}
\\ Or just using the list$()
For i=0 to Count-1 : Print List$(i) : Next i
declare ObjRegEx Nothing
End
Sub DisplayFunctions(x)
Local cc=param(x), ec=each(cc)
while ec {
Print eval$(ec) ' print every function/property of object x
}
End Sub
}
Checkit
 
 
 
Anonymous user