Jump to content

regexp back-reference swap around


Recommended Posts

I've tried for hours to figure this out and I just don't seem to get it. :idea: First some code which nearly works, but not quite.

$s_html = StringRegExpReplace($s_html, '[.),;:?!]+\</a>', '</a>' & '\0')

I want the punctuation (or end bracket) to end up on the other side of the </a> tag. I thought it would be easy to figure out. So I start with two groups: firstly some punctuation, in the order that it appears, and secondly the html tag. So what's the problem, I have the option to do as many as 10 back-references, it should be very straight forward. Well I have tried so many combinations now and I don't have a clue how to do it. I have a feeling that I should have something like this:

$s_html = StringRegExpReplace($s_html, '[.),;:?!]+[(</a>)]', '\1' & '\0')

But that doesn't do much. The problem seems to be that I am not separating the groups properly. How does one back-reference 2+ groups? And in this particular case, how can I convert this string mylink.com)?</a> into this one mylink.com</a>)?

I hope the question is clear. It's just a swap around job.

Edited by czardas
Link to comment
Share on other sites

If it helps,

Using your exact example

$sRtn = StringRegExpReplace("mylink.com</a>)?", "(.+\.\w+)(</a>)(.*)", "$1$3$2")
MsgBox(0, "Result", $sRtn)

We would really have to see more of an actual link if you can't figure it out from here.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

If it helps,

Using your exact example

$sRtn = StringRegExpReplace("mylink.com</a>)?", "(.+\.\w+)(</a>)(.*)", "$1$3$2")
MsgBox(0, "Result", $sRtn)

We would really have to see more of an actual link if you can't figure it out from here.

Thanks GEOSoft, however it doesn't have the desired effect in it's present form. I will have to examine it a bit deeper tomorrow, because it's quite late here and I'm pretty tired. Perhaps that's why my question was badly put.

Just to give you an idea: It isn't any particular link, but rather a number of badly formatted random links that I have created during another process. This corruption may be difficult to avoid: as it is uncertain how the URL ends: it could be .com, .org .net, perhaps a number or some other character. The idea is that the link occurs in some paragraph of plain text which is to be converted to html. Using space as an escape character to mark the end of a URL will only work sometimes. In plain text links might be separated by commas (shock horror) or appear at the end of a sentence. This is where the displacment of punctuation comes in. I thought I had this thing working a few hours ago, and was just about to post it in example scripts when I realized it was broke. Since then I have spent all night trying to fix it. Perhaps I can do something with StringBetween, but I'll leave it until the morning now :yawn: Thanks again, all the same, :idea:

Edited by czardas
Link to comment
Share on other sites

No problem.

Go to the Blog link in my sig and look at the post from about 3 or 4 days ago.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

No problem.

Go to the Blog link in my sig and look at the post from about 3 or 4 days ago.

I didn't get much time to look into this last week, hence the delay of my response and bumping a week old thread. GEOSoft you gave me exacctly what I asked for, ie an example which swaps the order of back-references - so that's great, cheers! :idea:

I noticed your website AutoIt Central previously, and I like it a lot. I would like to post a link to it on Czardas Hotel, with your permission of course.

Link to comment
Share on other sites

Glad it worked out for you.

Certainly you have my permission to link to the site.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Glad it worked out for you.

Certainly you have my permission to link to the site.

Well I still have a lot to learn. :)

I have created a banner for the link. I hope it meets your approval. You can see it on czardas hotel, and I have also posted it in the chat forum. See the topic: Web Banner Project. :idea:

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