Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

RegEx in VBA (VBS)



  • Please log in to reply
3 replies to this topic
Hamlet
  • Members
  • 302 posts
  • Last active: Mar 23 2014 03:37 PM
  • Joined: 22 Jan 2009
I made a script like this;
Yes, It is not working. Because, I am not good at this kind of late binding RegEx codings.
wd  := ComObjCreate( "Word.Application" )
wd.Visible := 1, wd.Activate
wd.Documents.Add
wd.ActiveDocument.Content.InsertAfter( "I like Grapes" )
 
RX := wd.CreateObject( "VBScript.RegExp" )   
RX.Pattern := "[Apple|Banana|Grape]"

MsgBox % RX.test( ActiveDocument.Content ) ? "OK" : "Nop"
Actually, I want to use VBA code like this;

Set RX = New regEXP  ; Early bindings

But, It is... way difficult for me to port into AHK. I have no clue how to handle VBA "Set" sentence in AHK.

Can anybody have any hints or someting ??


Above tries are useing Microsoft VBScript Regular Expressions 5.5.
Is there any way to solve VBA reg ex problems with different way(s) ?

Thanks..

Hamlet
  • Members
  • 302 posts
  • Last active: Mar 23 2014 03:37 PM
  • Joined: 22 Jan 2009

And, How can I handle;

On Error Resume Next
in AHK ?

I am using ;

wd.DisplayAlerts := 0
But, in some case, it is useless.

Thanks again.

 

(SOLVED, just to use Try and Catch..)



Hamlet
  • Members
  • 302 posts
  • Last active: Mar 23 2014 03:37 PM
  • Joined: 22 Jan 2009
✓  Best Answer

Today, Finally, I found it.

Just for a  little FUN for me.

 


CNT =
(
123 abc 456 def
789 efgh 012 ijkl
)
REX  :=  ComObjCreate( "VBScript.RegExp" )
REX.Global  :=  True 
REX.IgnoreCase  :=  False
REX.Pattern  :=  "(\d+)\s*(\w+)"

COL  :=  REX.Execute( CNT)

Loop %  COL.Count
  LT1  .= COL.Item( A_Index - 1 ).Value  "`n"    ; Zero Based Offset

Loop %  COL.Count
  LT2  .= COL.Item( A_Index - 1 ).Submatches(0)
  
For EMT  in  COL
  LT3  .=  EMT.Value  "`n"
  
For EMT  in  COL
  LT4  .=  EMT.Submatches(1)
 
Msgbox % LT1 "`n`n" LT2 "`n`n" LT3  "`n`n"  LT4

Return


Hamlet
  • Members
  • 302 posts
  • Last active: Mar 23 2014 03:37 PM
  • Joined: 22 Jan 2009

Here,

 

Microsoft Beefs Up VBScript with Regular Expressions

http://msdn.microsof...y/ms974570.aspx