AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

RegEx help needed... - [Solved]

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
silveredge78



Joined: 25 Jul 2006
Posts: 382
Location: Midwest, USA

PostPosted: Fri Jul 18, 2008 8:07 pm    Post subject: RegEx help needed... - [Solved] Reply with quote

I am wanting to strip out several characters out of a string. I need to remove all

commas
periods
the word NULL
spaces
single & double quotes
left & right parenthesis
hyphens

from a string. I don't know RegEx expressions at all. I can do this with StringReplace, it just takes a LOT lines to do it, whereas I think this can be done with one RegEx statement.

Can someone offer some help on this? Can you try to break it down and explain what each component is so that I can learn and compare to the help file?

Thanks!
_________________
SilverEdge78


Last edited by silveredge78 on Fri Jul 18, 2008 10:31 pm; edited 1 time in total
Back to top
View user's profile Send private message
jaco0646



Joined: 07 Oct 2006
Posts: 582
Location: MN, USA

PostPosted: Fri Jul 18, 2008 8:48 pm    Post subject: Reply with quote

\W = any non-word characters
| = OR
(null)+ = all occurrences of the word "null"
Code:
string = s,t.rnull 'i"(n)g-
MsgBox,% RegExReplace(string,"\W|(null)+")


You could also replace \W with a bracketed list of the punctuation to remove, if other punctuation should be kept.
_________________
http://autohotkey.net/~jaco0646/
Back to top
View user's profile Send private message Visit poster's website
silveredge78



Joined: 25 Jul 2006
Posts: 382
Location: Midwest, USA

PostPosted: Fri Jul 18, 2008 10:31 pm    Post subject: Reply with quote

Exactly what I wanted!! Thanks! Instead of 8 lines of code or so, it's one. Smile Thanks for the explanation as well. Smile
_________________
SilverEdge78
Back to top
View user's profile Send private message
jaco0646



Joined: 07 Oct 2006
Posts: 582
Location: MN, USA

PostPosted: Fri Jul 18, 2008 11:01 pm    Post subject: Reply with quote

I should have added the i option as well, to make "null" case-insensitive, since you did have it in all caps.
Code:
string = s,t.rNull 'i"(n)g-
MsgBox,% RegExReplace(string,"i)\W|(null)+")

_________________
http://autohotkey.net/~jaco0646/
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group