How to use Microsoft VBScript Regular Expressions 1.0.RegExp

Luc_VanDyck
Member, Moderator, Administrator Posts: 3,633
I'm trying to use VBScript RegExp to locate order numbers in a given string:
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?
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)
0
Answers
-
Most VBS Arrays/collections start at 0, so try
FOR i := 0 TO autRegExpMatchColl.Count - 1 DO BEGIN
0 -
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)0 -
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.0 -
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)0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions