Note that there are some explanatory texts on larger screens.

plurals
  1. POpython regex, substitute patterns in a string
    primarykey
    data
    text
    <p>I want to replace some substrings in a string with wiki markup. E.g. I have a string</p> <pre><code>some other string before ; Methods {{columns-list|3| * [[Anomaly detection|Anomaly/outlier/change detection]] * [[Association rule learning]] * [[Statistical classification|Classification]] * [[Cluster analysis]] * [[Decision trees]] * [[Factor analysis]] * [[Neural Networks]] * [[Regression analysis]] * [[Structured data analysis (statistics)|Structured data analysis]] * [[Sequence mining]] * [[Text mining]] }} ; Application domains {{columns-list|3| * [[Analytics]] * [[Bioinformatics]] * [[Business intelligence]] * [[Data analysis]] * [[Data warehouse]] * [[Decision support system]] * [[Drug Discovery]] * [[Exploratory data analysis]] * [[Predictive analytics]] * [[Web mining]] }} some other string after </code></pre> <p>I want to replace the original substring by</p> <pre><code>[[Anomaly detection|Anomaly/outlier/change detection]] [[Association rule learning]] [[Statistical classification|Classification]] [[Cluster analysis]] [[Decision trees]] [[Factor analysis]] [[Neural Networks]] [[Regression analysis]] [[Structured data analysis (statistics)|Structured data analysis]] [[Sequence mining]] [[Text mining]] [[Analytics]] [[Bioinformatics]] [[Business intelligence]] [[Data analysis]] [[Data warehouse]] [[Decision support system]] [[Drug Discovery]] [[Exploratory data analysis]] [[Predictive analytics]] [[Web mining]] </code></pre> <p>I've tried some regex expressions to extract stuff in {{ }} first. But I always got None. </p> <p>ADD: The problem is that I'm only interested in the contents in [[]] which itself is in {{}}. I have some other occurrences of [[]] in other part of the string. </p> <p>So, how could I do this by using re.sub? Thanks</p> <p>ADD: current solution (ugly)</p> <pre><code>def regt(matchobj): #store matchobj.group(0) somewhere else, later on add them to the string #Next, another function will remove all {{}} alway return '' matches = re.sub(r'\[\[.*?\]\](?=[^{]*\}\})', regt,wiki_string2) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload