Sign in to follow this  
Followers 0
Starfighter

StringRegExpReplace and HTML-Tags

6 posts in this topic

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

Share this post


Link to post
Share on other sites



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]

Share this post


Link to post
Share on other sites

#3 ·  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

Share this post


Link to post
Share on other sites

#4 ·  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

[center]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.[/center]

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Hi people,

Now the following code works perfect:

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

Many thanks

Share this post


Link to post
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
Sign in to follow this  
Followers 0