Jump to content

Need help with StringRegExpReplace


Annatsu
 Share

Recommended Posts

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

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 here
RegExp tutorial: enough to get started
PCRE 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

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 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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...