Starfighter Posted July 11, 2007 Share Posted July 11, 2007 Hello, I have a problem with the StringRegExpReplace function. A example in a HTML-File: </div>-official sites</div>Overview-taglines</div>-trailers</div>-posters</div> I want delete all strings between </div> and </div>, but only strings with "-" at the beginning. I want see this string after substitution: </div></div>Overview-taglines</div></div></div> I tried the following code: $ContentOfFileLocalMain=StringRegExpReplace($ContentOfFileLocalMain,'</div>-(.*?)</div>','</div></div>') This code doesn't work. Please help me. Thanks Link to comment Share on other sites More sharing options...
mikehunt114 Posted July 12, 2007 Share Posted July 12, 2007 I'm not a big regular expression guy...so how about just writing the HTML using an If (first character = '-') statement? Too many beers to help further.....maybe tomorrow. IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font] Link to comment Share on other sites More sharing options...
MisterBates Posted July 12, 2007 Share Posted July 12, 2007 (edited) Hello, I have a problem with the StringRegExpReplace function. A example in a HTML-File: </div>-official sites</div>Overview-taglines</div>-trailers</div>-posters</div> I want delete all strings between </div> and </div>, but only strings with "-" at the beginning. I want see this string after substitution: </div></div>Overview-taglines</div></div></div>This works, but doesn't take care to replace *only* between </div> tags: $sOrig = '</div>-official sites</div>Overview-taglines</div>-trailers</div>-posters</div>' $sResult = StringRegExpReplace($sOrig, '>-[^<]*', '>') The problem is that you have overlapping patterns (one </div> may end a pattern and begin the next), so you'll probably need to use assertions - something I've not yet mastered. EDIT: OK, couldn't resist learning something new. This seems to work (note the change of </div> to </biv> for testing): $sOrig = '</biv>-official sites</div>Overview-taglines</div>-trailers</div>-posters</div>' $sResult = StringRegExpReplace($sOrig, '(?<=</div>)-[^<]*(?=</div>)', '') Edited July 12, 2007 by MisterBates [u]MisterBates[/u]_____________________________________________________Suspend/Resume Windows ScreensaverWatchWindows - Window watcher/loggerUDF: Click systray menu/submenu itemsUDF: Outlook Express Folder/Message handling (+ example code)HowTo: Multiple icons in one compiled script Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted July 12, 2007 Moderators Share Posted July 12, 2007 (edited) This works, but doesn't take care to replace *only* between </div> tags: $sOrig = '</div>-official sites</div>Overview-taglines</div>-trailers</div>-posters</div>' $sResult = StringRegExpReplace($sOrig, '>-[^<]*', '>') The problem is that you have overlapping patterns (one </div> may end a pattern and begin the next), so you'll probably need to use assertions - something I've not yet mastered. EDIT: OK, couldn't resist learning something new. This seems to work (note the change of </div> to </biv> for testing): $sOrig = '</biv>-official sites</div>Overview-taglines</div>-trailers</div>-posters</div>' $sResult = StringRegExpReplace($sOrig, '(?<=</div>)-[^<]*(?=</div>)', '')Nice, I hadn't played with them myself as of yet... after seeing the example, it's definately something to start looking at ... Edit: '(?<=</div>)-.*?(?=</div>)'works as well. Edited July 12, 2007 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Xenobiologist Posted July 12, 2007 Share Posted July 12, 2007 Hi, '(?<=>)-.*?(?=<)' So long, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
Starfighter Posted July 13, 2007 Author Share Posted July 13, 2007 Hi people, Now the following code works perfect: $ContentOfFileLocalMain=StringRegExpReplace($ContentOfFileLocalMain,'(?<=</div>)-.*?(?=</div>)','') Many thanks 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