Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8136209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:41:17+00:00 2026-06-06T10:41:17+00:00

The Issue I’m migrating wiki pages from the FlexWiki engine to the FOSwiki engine

  • 0

The Issue

I’m migrating wiki pages from the FlexWiki engine to the FOSwiki engine using Python regular expressions to handle the differences between the two engines’ markup languages.

The FlexWiki markup and the FOSwiki markup, for reference.

Most of the conversion works very well, except when I try to convert the renamed links.
Both wikis support renamed links in their markup.

For example, Flexwiki uses:

"Link To Wikipedia":[http://www.wikipedia.org/]

FOSwiki uses:

[[http://www.wikipedia.org/][Link To Wikipedia]]

Both of which produce a rewritten hyperlink.

I’m using the regular expression

renameLink = re.compile ("\"(?P<linkText>[^\"]+)\":\[(?P<linkTarget>[^\[\]]+)\]")

to parse out the link elements from the FlexWiki markup, which after running through something like

"Link Text":[LinkTarget]

is reliably producing groups

<linkText> = Link Text
<linkTarget = LinkTarget

My issue occurs when I try to use re.sub to insert the parsed content into the FOSwiki markup.

My experience with regular expressions isn’t anything to write home about, but I’m under the impression that, given the groups

<linkText> = Link text
<linkTarget = LinkTarget

a line like

line = renameLink.sub ( "[[\g<linkTarget>][\g<linkText>]]" , line )

should produce

[[LinkTarget][Link Text]]

However, in the output to the text files I’m getting

[[LinkTarget [[Link Text]]

which breaks the renamed links.

After a little bit of fiddling I managed a workaround, where

line = renameLink.sub ( "[[\g<linkTarget>][ [\g<linkText>]]" , line )

produces

[[LinkTarget][ [[Link Text]]

which, when displayed in FOSwiki looks like

[[Link Text

Which WORKS, but isn’t very pretty.

There are probably thousands of instances of these renamed links in the pages I’m trying to convert, so fixing it by hand isn’t any good.
For the record I’ve run the script under Python 2.5.4 and Python 2.7.3, and gotten the same results.

Am I missing something really obvious with the syntax? Or is there an easy workaround?

Solution

There wasn’t anything wrong with the original expression.

I started running through the other regex’s in my script and commented out lines I thought might be overlapping with the renamed-link expression. That appears to have done the trick, and as a semi-permanent fix I’ve separated the link-focused expressions and the other expressions into separate scripts, which I run one after another.

I guess them moral here is to double-check that you don’t have overlapping expressions.

Attempted Solutions (Just see Solution above)

String addition

line = renameLink.sub ( "[[\g<linkTarget>]" + "[\g<linkText>]]" , line )

produces

[[linkTarget [[Link Text]]

It doesn’t matter how you slice the concatenation, the result is the same.

Escaping the square brackets, e.g.

line = renameLink.sub ( "\[\[\g<linkTarget>\]\[\g<linkName>\]\]" , line )

produces

\[ [[LinkTarget\]] [Link Text\]\]
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T10:41:19+00:00Added an answer on June 6, 2026 at 10:41 am

    a line like

    line = renameLink.sub ( "[[\g<linkTarget>][\g<linkText>]]" , line )
    

    should produce

    [[LinkTarget][Link Text]]
    

    And it does. Example:

    line = r""""Link Text":[LinkTarget]"""
    renameLink = re.compile("\"(?P<linkText>[^\"]+)\":\[(?P<linkTarget>[^\[\]]+)\]")
    print(renameLink.sub ("[[\g<linkTarget>][\g<linkText>]]", line))
    

    Output:

    [[LinkTarget][Link Text]]
    

    You probably have issues elsewhere than your expression.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Performance issue, when generating around 800~ options from jSon object via javascript. Any suggestion,
Issue: I am using the Microsoft.Office.Interop.Excel library in an ASP.NET application, and I have
Issue We are using config transforms inside our solution. For example: Debug, Test, Staging,
Issue/Question : I'm using CodeIgniter to build an event calendar, and I have included
Issue I want to implement TransparencyChecker Interface which would verify that from any exchange
Issue: To avoid creating multiple objects or multiple queries when possible. I am using
Issue I'm getting no output from a simple cout, whereas a printf will always
Issue I am using Castle Windsor as an IoC container in a Castle Monorail
ISSUE: I have an asp.net mvc 3 app. I'm using EF 4.1 and trying
issue during implementing twitter API. when i send a request using http://twitter.com/statuses/friends_timeline.xml i got

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.