How to use Microsoft VBScript Regular Expressions 1.0.RegExp

Luc_VanDyckLuc_VanDyck Member, Moderator, Administrator Posts: 3,633
I'm trying to use VBScript RegExp to locate order numbers in a given string:
Name                 DataType	  Subtype
autRegExp            Automation	'Microsoft VBScript Regular Expressions 1.0'.RegExp	
autRegExpMatchColl   Automation	'Microsoft VBScript Regular Expressions 1.0'.MatchCollection	
autRegExpMatch	    Automation	'Microsoft VBScript Regular Expressions 1.0'.Match
ltxtValue := 'AZERTYABCD-11-00234UIOP';
CREATE(autRegExp);
autRegExp.Pattern := 'ABCD-\d{2}-\d{5}';
autRegExpMatchColl := autRegExp.Execute(ltxtValue);
FOR i := 1 TO autRegExpMatchColl.Count DO BEGIN
  autRegExpMatch := ???;
  MESSAGE(autRegExpMatch.Value);
END;
I don't know how to assign an autRegExpMatchColl item to autRegExpMatch. Normally, I would write
autRegExpMatch := autRegExpMatchColl.Item(i);
but this gives a runtime-error: The requested member does not exist, or the call tried to set the valueof a read-only property.

I'm aware of the autRegExp.Test method which returns TRUE if the expression matches the inputstring, but I need to retrieve the order number.
I'm aware of a RegExp DLL which is available in the download-area, but I don't want to install extra components.
I'm aware of the use of STRPOS & COPYSTR functions for string-manipulation, but I want to use regular expressions as the format of the order number is user-definable.

Does someone has a clue?
No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)

Answers

  • MBergerMBerger Member Posts: 413
    Most VBS Arrays/collections start at 0, so try
    FOR i := 0 TO autRegExpMatchColl.Count - 1 DO BEGIN
    
  • Luc_VanDyckLuc_VanDyck Member, Moderator, Administrator Posts: 3,633
    Same error.

    Also with this code:
    autRegExpMatchColl := autRegExp.Execute(ltxtValue);
    autRegExpMatch := autRegExpMatchColl.Item(0);
    
    No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
  • IsakssonMiIsakssonMi Member Posts: 77
    It seems like 'Microsoft VBScript Regular Expressions 1.0'.Match is overwritten in the registry by 'Microsoft VBScript Regular Expressions 5.5'.Match.
    Try to change to version 5.5 instead, I guess you have both versions installed as well. That worked for me.
  • Luc_VanDyckLuc_VanDyck Member, Moderator, Administrator Posts: 3,633
    Thanks for the hint. I have changed the Automation variable to "Microsoft VBScript Regular Expressions 5.5", and now it works using this code:
    FOR i := 0 TO autRegExpMatchColl.Count - 1 DO BEGIN
      autRegExpMatch := autRegExpMatchColl.Item(i);
      MESSAGE(autRegExpMatch.Value);
    END;
    
    No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
Sign In or Register to comment.