Note that there are some explanatory texts on larger screens.

plurals
  1. POSlow regex in Python?
    text
    copied!<p>I'm trying to match these kinds of strings</p> <pre><code>{@csm.foo.bar} </code></pre> <p>without matching any of these</p> <pre><code>{@csm.foo.bar-@csm.ooga.booga} {@csm.foo.bar-42} </code></pre> <p>The regex I use is</p> <pre><code>r"\{@csm.((?:[a-zA-Z0-9_]+\.?)+)\}" </code></pre> <p>It gets dog slow if the string contains multiple matches. Why? It runs very fast if I take away the brace matching, like this</p> <pre><code>r"@csm.((?:[a-zA-Z0-9_]+\.?)+)" </code></pre> <p>but that's not what I want.</p> <p>Any ideas?</p> <p>Here is sample input:</p> <pre><code>&lt;dockLayout id="popup" y="0" x="0" width="{@csm.screenWidth}" height="{@csm.screenHeight}"&gt; &lt;dataNumber id="selopacity_Volt" name="selopacity_Volt" value="0" /&gt; &lt;dataNumber id="selopacity_Amp" name="selopacity_Amp" value="0" /&gt; &lt;animate trigger="{@m_ds_ML.VIMPBM_BatteryVoltage.valstr}" triggerOn="*" targetNode="selopacity_Volt" targetAttr="value" to="1" dur="0ms" ease="in" /&gt; &lt;animate trigger="{@m_ds_ML.VIMPBM_BatteryVoltage.valstr}" triggerOn="65024" targetNode="selopacity_Volt" targetAttr="value" to="0" dur="0ms" ease="in" /&gt; &lt;animate trigger="{@m_ds_ML.VIMPBM_BatteryCurrent.valstr}" triggerOn="*" targetNode="selopacity_Amp" targetAttr="value" to="1" dur="0ms" ease="in" /&gt; &lt;animate trigger="{@m_ds_ML.VIMPBM_BatteryCurrent.valstr}" triggerOn="65024" targetNode="selopacity_Amp" targetAttr="value" to="0" dur="0ms" ease="in" /&gt; &lt;dockLayout id="item" width="{@csm.screenWidth}" height="{@csm.screenHeight}" depth="-1" clip="false" xmlns="http://www.tat.se/kastor/kml" &gt; &lt;dockLayout id="list_item_title" x="0" width="{@csm.screenWidth}" height="{@csm.Gearselection.text_heght-@csm.pageVisualCP_y}"&gt; &lt;text id="volt_amp_text" x="0" ellipsize="false" font="{@csm.listUnselFont}" color="{@csm.itemUnselColor}" dockLayout.halign="left" dockLayout.valign="bottom" string="{ItemTitle}" /&gt; &lt;/dockLayout&gt; &lt;dockLayout id="gear_layout" y="0" x="0" width="{@csm.screenWidth}" height="{@csm.vmImage_y_gearselection-@csm.pageVisualCP_y}"&gt; &lt;image id="battery_image" x="0" dockLayout.halign="left" dockLayout.valign="bottom" opacity="1" src="{@m_MenuModel.Gauges.VoltAmpereMeter.image}"/&gt; &lt;/dockLayout&gt; &lt;!--DockLayout for Voltage Value--&gt; &lt;dockLayout id="volt_value" x="0" width="{@csm.VoltAmpereMeter.volt_value_x-@csm.VoltAmpereMeter.List_x}" height="{@csm.vmImage_y_gearselection-@csm.pageVisualCP_y}"&gt; &lt;text id="volt_value_text" x="0" opacity="{selopacity_Volt*selopacity_Amp}" ellipsize="false" font="{@csm.listUnselFont}" color="{@csm.itemSelColor}" dockLayout.halign="right" dockLayout.valign="bottom" string="{@m_ds_ML.VIMPBM_BatteryVoltage.valstr}" &gt; &lt;/text&gt; &lt;/dockLayout&gt; &lt;!--DockLayout for Voltage Unit--&gt; &lt;dockLayout id="volt_unit" x="{@csm.VoltAmpereMeter.volt_unit_x-@csm.VoltAmpereMeter.List_x}" width="{@csm.screenWidth}" height="{@csm.vmImage_y_gearselection-@csm.pageVisualCP_y}"&gt; &lt;text id="volt_unit_text" x="0" opacity="{selopacity_Volt*selopacity_Amp}" ellipsize="false" font="{@csm.listUnselFont}" color="{@csm.itemSelColor}" dockLayout.halign="left" dockLayout.valign="bottom" string="V" &gt; &lt;/text&gt; &lt;/dockLayout&gt; &lt;!--DockLayout for Ampere Value--&gt; &lt;dockLayout id="ampere_value" x="0" width="{@csm.VoltAmpereMeter.ampere_value_x-@csm.VoltAmpereMeter.List_x}" height="{@csm.vmImage_y_gearselection-@csm.pageVisualCP_y}"&gt; &lt;text id="ampere_value_text" x="0" opacity="{selopacity_Amp*selopacity_Volt}" ellipsize="false" font="{@csm.listUnselFont}" color="{@csm.itemSelColor}" dockLayout.halign="right" dockLayout.valign="bottom" string="{@m_ds_ML.VIMPBM_BatteryCurrent.valstr}" &gt; &lt;/text&gt; &lt;/dockLayout&gt; &lt;!--DockLayout for Ampere Unit--&gt; &lt;dockLayout id="ampere_unit" x="{@csm.VoltAmpereMeter.ampere_unit_x-@csm.VoltAmpereMeter.List_x}" width="{@csm.screenWidth}" height="{@csm.vmImage_y_gearselection-@csm.pageVisualCP_y}"&gt; &lt;text id="ampere_unit_text" x="0" opacity="{selopacity_Amp*selopacity_Volt}" ellipsize="false" font="{@csm.listUnselFont}" color="{@csm.itemSelColor}" dockLayout.halign="left" dockLayout.valign="bottom" string="A" &gt; &lt;/text&gt; &lt;/dockLayout&gt; &lt;!--DockLayout for containing Data Not Available text--&gt; &lt;dockLayout id="no_data_textline" x="{@csm.VoltAmpereMeter.List_x1-@csm.VoltAmpereMeter.List_x}" width="{@csm.screenWidth}" height="{@csm.vmImage_y_gearselection-@csm.pageVisualCP_y}"&gt; &lt;text id="no_data_text" x="0" opacity="{1-(selopacity_Amp*selopacity_Volt)}" ellipsize="false" font="{@csm.listSelFont}" color="{@csm.itemSelColor}" dockLayout.halign="left" dockLayout.valign="bottom" string="{text1}" &gt; &lt;/text&gt; &lt;/dockLayout&gt; &lt;!--&lt;rect id="test_rect1" x="{151-28}" y="0" width="1" height="240" opacity="1" fill="#00ff00" /&gt; &lt;rect id="test_rect1" x="{237-28}" y="0" width="1" height="240" opacity="1" fill="#00ff00" /&gt; &lt;rect id="test_rect1" x="{160-28}" y="0" width="1" height="240" opacity="1" fill="#00ff00" /&gt; &lt;rect id="test_rect1" x="{246-28}" y="0" width="1" height="240" opacity="1" fill="#00ff00" /&gt; &lt;rect id="test_rect8" x="0" y="{161-40}" width="320" height="1" opacity="1" fill="#00ff00" /&gt; &lt;rect id="test_rect1" x="{109-28}" y="0" width="1" height="240" opacity="1" fill="#00ff00" /&gt;--&gt; &lt;/dockLayout&gt; &lt;/dockLayout&gt; </code></pre>
 

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