3

I'm looking for a regex in VBscript that I can use on a ArcMap table. I know what it would look like in python:

pat =r'[0-9]{3,4}'

This filters all numeric characters from the string which have the length 3 to 4. So from AO123 you'd get 123 and from VO2-324C, 324.

What would be the equivalent in VBScript? How do I implement it with the RexExp Object? ArcGIS has a Field calculator that let's you execute VBScript code. But even the most simple regex (see screenshot) fails with the error message object needed: 're'.

enter image description here

Antonio Falciano
14.5k2 gold badges38 silver badges68 bronze badges
asked Aug 20, 2012 at 12:34
4
  • So.... what's the problem? What have you tried? Commented Aug 20, 2012 at 12:36
  • see my edit on the question for more detail. Commented Aug 20, 2012 at 12:48
  • This sounds like an ArcGIS question - how to get regex to run through VBScript in ArcGIS. Commented Aug 20, 2012 at 12:50
  • You're probably right. When I posted I thought I could use the re object, just found out that ArcGIS uses the 'ATL regular expression engine' - certainly a different com object. Sorry for the confusion, I try to move my question there. Thanks. Commented Aug 20, 2012 at 12:57

1 Answer 1

4

The error is because you have not initialized the RegExp Object using CreateObject. I am getting results with the below script.

Pre-Logic VBA Script Code

Set re = CreateObject("VBScript.RegExp")
With re
 .Pattern = "[0-9]{3,4}"
 .Global = False
 .IgnoreCase = False
End With
targetString = [OUDE_NAAM] 'your field here

Final Result Variable

re.Execute(targetString).Item(0)
answered Aug 20, 2012 at 14:37
1
  • Oh, heavenly sweetness. Nice. Didn't know you have to initialize the object like this. But what do I know about VBScript? Thanks mate, man of my Monday! Commented Aug 20, 2012 at 15:03

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.