deleting 0's from an attribute
IljaDeCoster
New Altair Community Member
Dear,
With in a proces i created an nominal attribute with examples like:
0001
0110
1010
0011
0111
1111
...
I would like to change this attribute deleting all the 0's before the first 1 (while keeping the 0's after the first 1). So the example should look like:
1
110
1010
11
111
1111
...
I tried with the replace operator and a regular axpression, but It seems I don't find the right one...
Thanks a lot,
Ilja
With in a proces i created an nominal attribute with examples like:
0001
0110
1010
0011
0111
1111
...
I would like to change this attribute deleting all the 0's before the first 1 (while keeping the 0's after the first 1). So the example should look like:
1
110
1010
11
111
1111
...
I tried with the replace operator and a regular axpression, but It seems I don't find the right one...
Thanks a lot,
Ilja
Tagged:
0
Answers
-
The Replace operator is the way to go. Please post your process setup so we can have a look at what is going wrong.
Best regards,
Marius0 -
So I was right to try with the replace operator. In that case my main issue would be to find the right regular expression - It seems I do have some issues to build them. And manuals on that?
I add the process here:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<process version="5.3.000">
<context>
<input/>
<output/>
<macros/>
</context>
<operator activated="true" class="process" compatibility="5.3.000" expanded="true" name="Process">
<process expanded="true" height="431" width="748">
<operator activated="true" class="retrieve" compatibility="5.3.000" expanded="true" height="60" name="Retrieve DvW_werkdata_DAFnaanalyse3 (2)" width="90" x="45" y="30">
<parameter key="repository_entry" value="DvW_werkdata_DAFnaanalyse3"/>
</operator>
<operator activated="true" class="format_numbers" compatibility="5.3.000" expanded="true" height="76" name="Format Numbers" width="90" x="179" y="120">
<parameter key="attribute_filter_type" value="subset"/>
<parameter key="attributes" value="|DAFstatusY01|DAFstatusY02|DAFstatusY03|DAFstatusY04|DAFstatusY05|DAFstatusY06|DAFstatusY07|DAFstatusY08|DAFstatusY09|DAFstatusY10|DAFstatusY11|DAFstatusY12|DAFstatusY13|DAFstatusY14|DAFstatusY15|DAFstatusY16|DAFstatusY17|DAFstatusY18|DAFstatusY19|DAFstatusY20"/>
<parameter key="format_type" value="integer"/>
<parameter key="locale" value="Dutch (Belgium)"/>
</operator>
<operator activated="true" class="subprocess" compatibility="5.3.000" expanded="true" height="76" name="Creating churncode carriere" width="90" x="313" y="120">
<process expanded="true" height="541" width="701">
<operator activated="true" class="generate_concatenation" compatibility="5.3.000" expanded="true" height="76" name="Generate Concatenation (2)" width="90" x="45" y="30">
<parameter key="first_attribute" value="DAFstatusY01"/>
<parameter key="second_attribute" value="DAFstatusY02"/>
<parameter key="trim_values" value="true"/>
</operator>
<operator activated="true" class="generate_concatenation" compatibility="5.3.000" expanded="true" height="76" name="Generate Concatenation" width="90" x="179" y="30">
<parameter key="first_attribute" value="DAFstatusY03"/>
<parameter key="second_attribute" value="DAFstatusY04"/>
<parameter key="trim_values" value="true"/>
</operator>
<operator activated="true" class="generate_concatenation" compatibility="5.3.000" expanded="true" height="76" name="Generate Concatenation (3)" width="90" x="313" y="30">
<parameter key="first_attribute" value="DAFstatusY05"/>
<parameter key="second_attribute" value="DAFstatusY06"/>
<parameter key="trim_values" value="true"/>
</operator>
<operator activated="true" class="generate_concatenation" compatibility="5.3.000" expanded="true" height="76" name="Generate Concatenation (4)" width="90" x="447" y="30">
<parameter key="first_attribute" value="DAFstatusY07"/>
<parameter key="second_attribute" value="DAFstatusY08"/>
<parameter key="trim_values" value="true"/>
</operator>
<operator activated="true" class="generate_concatenation" compatibility="5.3.000" expanded="true" height="76" name="Generate Concatenation (5)" width="90" x="581" y="30">
<parameter key="first_attribute" value="DAFstatusY09"/>
<parameter key="second_attribute" value="DAFstatusY10"/>
<parameter key="trim_values" value="true"/>
</operator>
<operator activated="true" class="generate_concatenation" compatibility="5.3.000" expanded="true" height="76" name="Generate Concatenation (6)" width="90" x="45" y="120">
<parameter key="first_attribute" value="DAFstatusY11"/>
<parameter key="second_attribute" value="DAFstatusY12"/>
<parameter key="trim_values" value="true"/>
</operator>
<operator activated="true" class="generate_concatenation" compatibility="5.3.000" expanded="true" height="76" name="Generate Concatenation (7)" width="90" x="179" y="120">
<parameter key="first_attribute" value="DAFstatusY13"/>
<parameter key="second_attribute" value="DAFstatusY14"/>
<parameter key="trim_values" value="true"/>
</operator>
<operator activated="true" class="generate_concatenation" compatibility="5.3.000" expanded="true" height="76" name="Generate Concatenation (8)" width="90" x="313" y="120">
<parameter key="first_attribute" value="DAFstatusY15"/>
<parameter key="second_attribute" value="DAFstatusY16"/>
<parameter key="trim_values" value="true"/>
</operator>
<operator activated="true" class="generate_concatenation" compatibility="5.3.000" expanded="true" height="76" name="Generate Concatenation (9)" width="90" x="447" y="120">
<parameter key="first_attribute" value="DAFstatusY17"/>
<parameter key="second_attribute" value="DAFstatusY18"/>
<parameter key="trim_values" value="true"/>
</operator>
<operator activated="true" class="generate_concatenation" compatibility="5.3.000" expanded="true" height="76" name="Generate Concatenation (10)" width="90" x="581" y="120">
<parameter key="first_attribute" value="DAFstatusY19"/>
<parameter key="second_attribute" value="DAFstatusY20"/>
<parameter key="trim_values" value="true"/>
</operator>
<operator activated="true" class="generate_concatenation" compatibility="5.3.000" expanded="true" height="76" name="Generate Concatenation (11)" width="90" x="45" y="255">
<parameter key="first_attribute" value="DAFstatusY01_DAFstatusY02"/>
<parameter key="second_attribute" value="DAFstatusY03_DAFstatusY04"/>
<parameter key="trim_values" value="true"/>
</operator>
<operator activated="true" class="generate_concatenation" compatibility="5.3.000" expanded="true" height="76" name="Generate Concatenation (12)" width="90" x="179" y="255">
<parameter key="first_attribute" value="DAFstatusY05_DAFstatusY06"/>
<parameter key="second_attribute" value="DAFstatusY07_DAFstatusY08"/>
<parameter key="trim_values" value="true"/>
</operator>
<operator activated="true" class="generate_concatenation" compatibility="5.3.000" expanded="true" height="76" name="Generate Concatenation (14)" width="90" x="313" y="255">
<parameter key="first_attribute" value="DAFstatusY09_DAFstatusY10"/>
<parameter key="second_attribute" value="DAFstatusY11_DAFstatusY12"/>
<parameter key="trim_values" value="true"/>
</operator>
<operator activated="true" class="generate_concatenation" compatibility="5.3.000" expanded="true" height="76" name="Generate Concatenation (13)" width="90" x="447" y="255">
<parameter key="first_attribute" value="DAFstatusY13_DAFstatusY14"/>
<parameter key="second_attribute" value="DAFstatusY15_DAFstatusY16"/>
<parameter key="trim_values" value="true"/>
</operator>
<operator activated="true" class="generate_concatenation" compatibility="5.3.000" expanded="true" height="76" name="Generate Concatenation (15)" width="90" x="581" y="255">
<parameter key="first_attribute" value="DAFstatusY17_DAFstatusY18"/>
<parameter key="second_attribute" value="DAFstatusY19_DAFstatusY20"/>
<parameter key="trim_values" value="true"/>
</operator>
<operator activated="true" class="rename" compatibility="5.3.000" expanded="true" height="76" name="Rename" width="90" x="45" y="345">
<parameter key="old_name" value="DAFstatusY01_DAFstatusY02_DAFstatusY03_DAFstatusY04"/>
<parameter key="new_name" value="DAFChurn1"/>
<list key="rename_additional_attributes">
<parameter key="DAFstatusY05_DAFstatusY06_DAFstatusY07_DAFstatusY08" value="DAFChurn2"/>
<parameter key="DAFstatusY09_DAFstatusY10_DAFstatusY11_DAFstatusY12" value="DAFChurn3"/>
<parameter key="DAFstatusY13_DAFstatusY14_DAFstatusY15_DAFstatusY16" value="DAFChurn4"/>
<parameter key="DAFstatusY17_DAFstatusY18_DAFstatusY19_DAFstatusY20" value="DAFChurn5"/>
</list>
</operator>
<operator activated="true" class="generate_concatenation" compatibility="5.3.000" expanded="true" height="76" name="Generate Concatenation (16)" width="90" x="179" y="345">
<parameter key="first_attribute" value="DAFChurn1"/>
<parameter key="second_attribute" value="DAFChurn2"/>
</operator>
<operator activated="true" class="generate_concatenation" compatibility="5.3.000" expanded="true" height="76" name="Generate Concatenation (17)" width="90" x="313" y="345">
<parameter key="first_attribute" value="DAFChurn1_DAFChurn2"/>
<parameter key="second_attribute" value="DAFChurn3"/>
</operator>
<operator activated="true" class="generate_concatenation" compatibility="5.3.000" expanded="true" height="76" name="Generate Concatenation (18)" width="90" x="447" y="345">
<parameter key="first_attribute" value="DAFChurn1_DAFChurn2_DAFChurn3"/>
<parameter key="second_attribute" value="DAFChurn4"/>
</operator>
<operator activated="true" class="generate_concatenation" compatibility="5.3.000" expanded="true" height="76" name="Generate Concatenation (19)" width="90" x="581" y="345">
<parameter key="first_attribute" value="DAFChurn1_DAFChurn2_DAFChurn3_DAFChurn4"/>
<parameter key="second_attribute" value="DAFChurn5"/>
</operator>
<operator activated="true" class="rename" compatibility="5.3.000" expanded="true" height="76" name="Rename (2)" width="90" x="45" y="435">
<parameter key="old_name" value="DAFChurn1_DAFChurn2_DAFChurn3_DAFChurn4_DAFChurn5"/>
<parameter key="new_name" value="DAFChurncarriere"/>
<list key="rename_additional_attributes"/>
</operator>
<operator activated="true" class="generate_attributes" compatibility="5.3.000" expanded="true" height="76" name="Generate Attributes (2)" width="90" x="179" y="435">
<list key="function_descriptions">
<parameter key="DAFChurncodecarriere" value="replace(DAFChurncarriere,"_","")"/>
</list>
</operator>
<operator activated="true" class="select_attributes" compatibility="5.3.000" expanded="true" height="76" name="Select Attributes" width="90" x="313" y="435">
<parameter key="attribute_filter_type" value="subset"/>
<parameter key="attributes" value="|DAFstatusY01_DAFstatusY02|DAFstatusY03_DAFstatusY04|DAFstatusY05_DAFstatusY06|DAFstatusY07_DAFstatusY08|DAFstatusY09_DAFstatusY10|DAFstatusY11_DAFstatusY12|DAFstatusY13_DAFstatusY14|DAFstatusY15_DAFstatusY16|DAFstatusY17_DAFstatusY18|DAFstatusY19_DAFstatusY20|DAFChurn1|DAFChurn2|DAFChurn3|DAFChurn4|DAFChurn5|DAFChurn1_DAFChurn2|DAFChurn1_DAFChurn2_DAFChurn3|DAFChurn1_DAFChurn2_DAFChurn3_DAFChurn4|DAFChurn1_DAFChurn2_DAFChurn3_DAFChurn4_DAFChurn5|DAFChurncarriere"/>
<parameter key="invert_selection" value="true"/>
</operator>
<connect from_port="in 1" to_op="Generate Concatenation (2)" to_port="example set input"/>
<connect from_op="Generate Concatenation (2)" from_port="example set output" to_op="Generate Concatenation" to_port="example set input"/>
<connect from_op="Generate Concatenation" from_port="example set output" to_op="Generate Concatenation (3)" to_port="example set input"/>
<connect from_op="Generate Concatenation (3)" from_port="example set output" to_op="Generate Concatenation (4)" to_port="example set input"/>
<connect from_op="Generate Concatenation (4)" from_port="example set output" to_op="Generate Concatenation (5)" to_port="example set input"/>
<connect from_op="Generate Concatenation (5)" from_port="example set output" to_op="Generate Concatenation (6)" to_port="example set input"/>
<connect from_op="Generate Concatenation (6)" from_port="example set output" to_op="Generate Concatenation (7)" to_port="example set input"/>
<connect from_op="Generate Concatenation (7)" from_port="example set output" to_op="Generate Concatenation (8)" to_port="example set input"/>
<connect from_op="Generate Concatenation (8)" from_port="example set output" to_op="Generate Concatenation (9)" to_port="example set input"/>
<connect from_op="Generate Concatenation (9)" from_port="example set output" to_op="Generate Concatenation (10)" to_port="example set input"/>
<connect from_op="Generate Concatenation (10)" from_port="example set output" to_op="Generate Concatenation (11)" to_port="example set input"/>
<connect from_op="Generate Concatenation (11)" from_port="example set output" to_op="Generate Concatenation (12)" to_port="example set input"/>
<connect from_op="Generate Concatenation (12)" from_port="example set output" to_op="Generate Concatenation (14)" to_port="example set input"/>
<connect from_op="Generate Concatenation (14)" from_port="example set output" to_op="Generate Concatenation (13)" to_port="example set input"/>
<connect from_op="Generate Concatenation (13)" from_port="example set output" to_op="Generate Concatenation (15)" to_port="example set input"/>
<connect from_op="Generate Concatenation (15)" from_port="example set output" to_op="Rename" to_port="example set input"/>
<connect from_op="Rename" from_port="example set output" to_op="Generate Concatenation (16)" to_port="example set input"/>
<connect from_op="Generate Concatenation (16)" from_port="example set output" to_op="Generate Concatenation (17)" to_port="example set input"/>
<connect from_op="Generate Concatenation (17)" from_port="example set output" to_op="Generate Concatenation (18)" to_port="example set input"/>
<connect from_op="Generate Concatenation (18)" from_port="example set output" to_op="Generate Concatenation (19)" to_port="example set input"/>
<connect from_op="Generate Concatenation (19)" from_port="example set output" to_op="Rename (2)" to_port="example set input"/>
<connect from_op="Rename (2)" from_port="example set output" to_op="Generate Attributes (2)" to_port="example set input"/>
<connect from_op="Generate Attributes (2)" from_port="example set output" to_op="Select Attributes" to_port="example set input"/>
<connect from_op="Select Attributes" from_port="example set output" to_port="out 1"/>
<portSpacing port="source_in 1" spacing="0"/>
<portSpacing port="source_in 2" spacing="0"/>
<portSpacing port="sink_out 1" spacing="0"/>
<portSpacing port="sink_out 2" spacing="0"/>
</process>
</operator>
<operator activated="true" class="generate_copy" compatibility="5.3.000" expanded="true" height="76" name="Generate Copy" width="90" x="447" y="120">
<parameter key="attribute_name" value="DAFChurncodecarriere"/>
<parameter key="new_name" value="DAFChurncodecarriere2"/>
</operator>
<operator activated="true" class="order_attributes" compatibility="5.3.000" expanded="true" height="76" name="Reorder Attributes" width="90" x="581" y="120">
<parameter key="attribute_ordering" value="DAFChurncodecarriere|DAFChurncodecarriere2"/>
</operator>
<operator activated="true" class="replace" compatibility="5.3.000" expanded="true" height="76" name="Replace" width="90" x="581" y="210">
<parameter key="attribute_filter_type" value="single"/>
<parameter key="attribute" value="DAFChurncodecarriere2"/>
<parameter key="replace_what" value=""000001"\d[0-9]"/>
<parameter key="replace_by" value=""1"\d[0-9]"/>
</operator>
<connect from_op="Retrieve DvW_werkdata_DAFnaanalyse3 (2)" from_port="output" to_op="Format Numbers" to_port="example set input"/>
<connect from_op="Format Numbers" from_port="example set output" to_op="Creating churncode carriere" to_port="in 1"/>
<connect from_op="Creating churncode carriere" from_port="out 1" to_op="Generate Copy" to_port="example set input"/>
<connect from_op="Generate Copy" from_port="example set output" to_op="Reorder Attributes" to_port="example set input"/>
<connect from_op="Reorder Attributes" from_port="example set output" to_op="Replace" to_port="example set input"/>
<portSpacing port="source_input 1" spacing="0"/>
<portSpacing port="sink_result 1" spacing="0"/>
</process>
</operator>
</process>
[ /code]0 -
Just replace "^0+" with "" (empty string), both without quotes. The caret symbol requests that the match must be at the beginning of the string.
Best regards,
Marius0