Regular expressions: Difference between revisions
Content added Content deleted
(added Ol) |
|||
Line 1,091: | Line 1,091: | ||
We can use named parameters (for Word) Try {Method Documents, "add", "", DocumentType:=WdNewWebPage as doc1} |
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> |
<lang M2000 Interpreter> |
||
Line 1,113: | Line 1,115: | ||
Print RegEx.Replace$("Myer Ken, Vice President, Sales and Services", " ") |
Print RegEx.Replace$("Myer Ken, Vice President, Sales and Services", " ") |
||
pattern$="(\d{3})-(\d{3})-(\d{4})" |
pattern$="(\d{3})-(\d{3})-(\d{4})" |
||
Method ObjRegEx, "Execute", "555-123-4567, 555-943-6717" as MyMatches |
Method ObjRegEx, "Execute", "555-123-4567, 555-943-6717" as MyMatches |
||
Print Type$(MyMatches) ' it is a IMatchCollection2 |
Print Type$(MyMatches) ' it is a IMatchCollection2 |
||
With MyMatches, "Count" as count, "Item" as List$() |
With MyMatches, "Count" as count, "Item" as List$() |
||
For i=0 to Count-1 : Print List$(i) : Next i |
For i=0 to Count-1 : Print List$(i) : Next i |
||
Print RegEx.Replace$("555-123-4567, 555-943-6717", "($1) $2-$3") |
Print RegEx.Replace$("555-123-4567, 555-943-6717", "($1) $2-$3") |
||
Pattern$ = "(\S+), (\S+)" |
Pattern$ = "(\S+), (\S+)" |
||
Print RegEx.Replace$("Myer, Ken", "$2 $1") |
Print RegEx.Replace$("Myer, Ken", "$2 $1") |
||
Method ObjRegEx, "Execute", "Myer, Ken" as MyMatches |
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 |
For i=0 to Count-1 : Print List$(i) : Next i |
||
declare ObjRegEx Nothing |
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 |
Checkit |
||