Solved

Vbscript Case Statment using multiple regular Expression pattern

Posted on 2009-05-06
4
1,629 Views
Last Modified: 2012-05-06
I need to use a case statement or If - Then structure to change account numbers.  I have a search string that uses a long regular expression statement.  ITs actually 3 "filters" with the " | " or statement.  That part works.  i have echoed back what it finds there adn its doing its job.  

The problem is, i need to do different things to clean up the account number based on which regexpr was used to find that number.  Right now i have only 3 possibilities...but it could grow to much more.  SO, i need to use a case or If - then statement to check and see if the account number it finds is = to which regexpr pattern.  I know this code is wrong and does not work..but gives teh idea of what i'm trying to do

I am decent with vbscript, but cannot figure out the logic for this answer.
Thanks in advance
' Try to find first type of account number

         ' Find Account Number inside Text File

         Set inFile = objFileSys.openTextFile(txtFile,1,True)

         Set objRegExpr = New RegExp

         objRegExpr.Global = True

         objRegExpr.Pattern = "[0-9]{6}[\s][0-9]{7}[\s][0-9]{5}|[0-9]{3}\-[0-9]{3}\-[0-9]{3}\-[0-9]{1}|[6][0-9]{15}"

         

         Set varPatternA = New RegExp

		 varPatternA.Global = True

		 varPatternA.Pattern = "[0-9]{6}[\s][0-9]{7}[\s][0-9]{5}"
 

		 Set varPatternB = New RegExp

		 varPatternB.Global = True

		 varPatternB.Pattern = "[0-9]{3}\-[0-9]{3}\-[0-9]{3}\-[0-9]{1}"

		 

		 Set varPatternC = New RegExp

		 varPatternC.Global = True

		 varPatternC.Pattern = "[6][0-9]{15}"

        

	 ' finds account number pattern in file  "* ################"

         
 

	 Do Until infile.AtEndOfStream

            Set regExprMatch = objRegExpr.Execute (infile.readline)

	    	For Each objMatch in regExprMatch

				

		   If objMatch.Value = varPatternA Then

		         docAccountNumber = objMatch.value

                         ' Trim spaces out of AccNum

                          regEx.Pattern = "\s"

                          docAccountNumber = Trim(regEx.Replace(docAccountNumber, ""))

                          docAccountNumber = Left(docAccountNumber,15)

		     End IF

				

		If objMatch.Value = varPatternB.Pattern Then                

                	docAccountNumber = objMatch.value

                       ' Trim "-" out of the account Number

                        regEx.Pattern = "\-"

                        docAccountNumber = Trim(regEx.Replace(docAccountNumber, ""))

                        ' Add  Header Code

                        docAccountNumber = "123456" & docAccountNumber

                End If

                

		If objMatch.Value = varPatternC.Pattern Then                

                	docAccountNumber = objMatch.Value

                End If

Open in new window

0
Comment
Question by:KentuckyDataService
  • 3
4 Comments
 
LVL 27

Accepted Solution

by:
ddrudik earned 500 total points
ID: 24326463
In ASP VBSCRIPT you would normally use a .Test that would return true/false if a given regex would match.  Not sure I follow your question though.
<%

Set regEx = New RegExp

regEx.Global = True

regEx.IgnoreCase = True

regEx.MultiLine = True

teststring = "your string"

regEx.Pattern = "^[a-z]+$"

Set Test = regEx.Test(teststring)

%>

Open in new window

0
 
LVL 27

Expert Comment

by:ddrudik
ID: 24641077
KentuckyDataService, did that answer your question?  Let me know if I can help further.
0
 
LVL 1

Author Comment

by:KentuckyDataService
ID: 25068469
I think that could have worked, i will award you the points.  I ended up using 2 regular expressions using the OR " | " for it.  Not the most efficient way, but it worked.
0
 
LVL 27

Expert Comment

by:ddrudik
ID: 25069020
Thanks for the question and the points.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Command to modify Registry entry 5 98
VBS to check if Visio file open and if so close it 4 51
Bulk Reorder File Names 4 56
regx  exclude  pattern 6 28
Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now