Annatsu Posted January 26, 2016 Share Posted January 26, 2016 Hey guys! I'm a totally noob when it comes to Regular Expression uses. I'm trying to make an AutoIt Script that modifies .html files using StringReplace's. However, now i'm trying to modify "background-color: xxxxx;" and can't find a way to do it with the normal StringReplace function. Can someone help me with this? I already tried this: StringRegExpReplace('<div style="background-color: aqua; position: relative;"', "background: (\D);", "background: none;") I thought that using the \D it would capture anything that comes after "background-color:" and then replace it... But it doesn't work. Can someone help me with this? I already read some documentation on Regular Expression, but haven't had luck. Thanks in advance. Annatsu Link to comment Share on other sites More sharing options...
kylomas Posted January 26, 2016 Share Posted January 26, 2016 annatsu, Welcome to the forum! Could you please post a complete example of the text file you are trying to change and what you want to change it to? kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
jchd Posted January 27, 2016 Share Posted January 27, 2016 Annatsu, \D matches a single non-digit and that's not what you want. Local $sRes = StringRegExpReplace('<div style="background-color: aqua; position: relative;"', "(?<=background-color: )[^;]*?(?=;)", "none") ConsoleWrite($sRes & @LF) This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
jdelaney Posted January 27, 2016 Share Posted January 27, 2016 (edited) Are you working in an active browser? You can update the DOM object, and bypass the regexp altogether. If the HTML you are modifying is simple, then you can even use an XMLDom to modify the value. Both these suggestions will work 100% of the time, where a regexp needs to constantly be tinkered with as new scenarios come up. Edited January 27, 2016 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. 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