llolslim Posted July 16, 2010 Share Posted July 16, 2010 (edited) Hi guysI have a list of words that I need to replace certain characters inthere are three different sections that need to be replacedthese are the characters that need to be replaced:1."/'" to be replaced by "%27"2."+" to be replaced by "%2B"3." (" to be replaced by "+(" <- there is a space before the bracket that needs to be replaced by a +$slashdash = "/'" $plus = "+" $spacebracket = " (" $input = StringRegExpReplace($input, "/'", "%27") ;works $input = StringRegExpReplace($input, $plus, "%2B") ;doesn't work $input = StringRegExpReplace($input, $spacebracket, "+(");doesn't workI have hundreds of words in the list for examplewood\'brown = wood%27brownbrick+2 = brick%2B2slate (new) = slate+(new)so each one needs to be run through all three of the StringRegExpReplacemy question is how can I get 2. and 3. to hope that makes sense and someone can helpmany thankslaurie Edited July 16, 2010 by llolslim Link to comment Share on other sites More sharing options...
GEOSoft Posted July 16, 2010 Share Posted July 16, 2010 (edited) Those are special characters within the regEx engine and as such should be escaped either with a "\" or the\Q\E sequence $input = StringRegExpReplace($input, "\Q" & $plus & "\E", "%2B") $input = StringRegExpReplace($input, "\Q" & $spacebracket & "\E", "+(") EDIT: I only showed the one method but you might prefer the other one so here it is. $slashdash = "/'" $plus = "\+" $spacebracket = " \(" $input = StringRegExpReplace($input, "/'", "%27") $input = StringRegExpReplace($input, $plus, "%2B") $input = StringRegExpReplace($input, $spacebracket, "+(") Edited July 16, 2010 by GEOSoft George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
DicatoroftheUSA Posted July 16, 2010 Share Posted July 16, 2010 Fromhttp://www.regular-expressions.info/characters.htmlIf you want to use any of these characters as a literal in a regex, you need to escape them with a backslash. If you want to match 1+1=2, the correct regex is 1\+1=2. Otherwise, the plus sign will have a special meaning. Statism is violence, Taxation is theft. Autoit Wiki Link to comment Share on other sites More sharing options...
llolslim Posted July 16, 2010 Author Share Posted July 16, 2010 Those are special characters within the regEx engine and as such should be escaped either with a "\" or the\Q\E sequence $input = StringRegExpReplace($input, "\Q" & $plus & "\E", "%2B") $input = StringRegExpReplace($input, "\Q" & $spacebracket & "\E", "+(") EDIT: I only showed the one method but you might prefer the other one so here it is. $slashdash = "/'" $plus = "\+" $spacebracket = " \(" $input = StringRegExpReplace($input, "/'", "%27") $input = StringRegExpReplace($input, $plus, "%2B") $input = StringRegExpReplace($input, $spacebracket, "+(") escaping with / is much easier for me to read, so that's great, thank you From http://www.regular-expressions.info/characters.html that makes it very clear as well, so that's a great help also, thank you. Link to comment Share on other sites More sharing options...
GEOSoft Posted July 16, 2010 Share Posted July 16, 2010 Glad it worked. You can easily test regExps with the toolkit in my signature. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now