Jump to content

Recommended Posts

Posted

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

Posted

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]
Posted (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 by MisterBates
  • Moderators
Posted (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 ... :whistle:

Edit:

'(?<=</div>)-.*?(?=</div>)'
works as well. Edited 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.

Posted

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

Posted

Hi people,

Now the following code works perfect:

$ContentOfFileLocalMain=StringRegExpReplace($ContentOfFileLocalMain,'(?<=</div>)-.*?(?=</div>)','')

Many thanks

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
×
×
  • Create New...