dcsimg
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: VBScript
Expertise: Intermediate
Jul 28, 2004

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Extracting Parameters from a File Using Regular Expressions

Extracting parameters from a file using regular expressions can be a very effective and practical way of doing things. Suppose, for instance, that you need a logon script that maps drives depending on the computer's sites. A custom parameter file could look like this:

Site1.MapDrive_X=\\server1\share1
Site1.MapDrive_Y=\\server1\share2
Site2.MapDrive_X=\\server3\share1
Site3.MapDrive_Z=\\server4\share4
Extracting those parameters would be as easy as getting the actual site name, building a regular expression, and looping on found matches. Assuming that you've got a ParameterFileContent variable already available, you'd have something like this:

set oRegExp = new RegExp
oRegExp.Global = True 'To get all matches
oRegExp.IgnoreCase = True 'We don't want to bother with case in our parameter file

'Mapping drives for the current ActiveDirectory site
Set oAdSysInfo = CreateObject("ADSystemInfo")
oRegExp.Pattern = oAdSysInfo.SiteName & "\.MapDrive_(\w)=(.*)" 
Set oMatchCol = oRegExp.Execute(ParameterFileContent)
For Each oMatch In oMatchCol '
  DriveName = oMatch.SubMatches(0) 'The \w from the first set of parenthesis
  SharePath = oMatch.SubMatches(1) 'The .* from the second set of parenthesis
  WScript.Echo("DriveName=" & DriveName & " SharePath=" & SharePath)
  WshNetwork.MapNetworkDrive DriveName & ":",SharePath,False
Next

Reuse the oRegExp object to process any other needed parameter...

GroupName2.RunApplication=\\server1\share1\Application1\Application1.exe
GroupName2.MapNetworkDrive_X=\\server1\share1  
Site1.SQLServerName=SQL01
Stephane Courcy Poitras
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date