Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Regular Expression Help

 
Logged in as: Guest
arrSession:exec spGetSession 2,3,35000
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> ASP >> Regular Expression Help
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Regular Expression Help - 5/31/2006 4:06:55 AM   
  imustbeanonymous

 

Posts: 4
Score: 0
Joined: 5/31/2006
Status: offline
I'm trying to use a regular expression to strip all non alphanumeric characters from a string.

For example, I have a string (filename) like:

John's bike1.jpg

I want to RegEx it into

Johns_bike1.jpg

In plain english it would say; remove all special characters, except periods, and replace all whitespace with underscores.

I've tried 20-some different expressions and I can't get it right.

Any help is much appreciated. 
 
 
Post #: 1
 
 RE: Regular Expression Help - 5/31/2006 6:40:05 AM   
  ebgreen


Posts: 4970
Score: 31
Joined: 7/12/2005
Status: offline
The problem you are going to have is the . for the extension. you won't want to drop it. What I would do is this:

1) Use Left() and Instr() to get everything up to the last .
2) take that string and hand it to this function:
Function FixChars(strString)
   Set oRE = New Regexp
   oRE.Global = True
  
   oRE.Pattern = " "
   strTest = oRE.Replace(strString, "_")
   oRE.Pattern = "\W"
   FixChars = oRE.Replace(strString, "")
End Function

3) Now put the fixed string back together with the extension from the original string.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to imustbeanonymous)
 
 
Post #: 2
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> ASP >> Regular Expression Help Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts