MAP operator not capturing from RegEx

ClaraCaba
New Altair Community Member
Hello,
I have a collection of attributes that have values like 1 ~ 5, 5 ~ 20, and so on, and I would like to use the Map operator to map those values into something of the type 1 - 5, 5 - 20. Thus, I would like to replace the ~ symbol by the - symbol.
Anyway, like I said, I am using the Map operator to do so and, having selected my attribute, I introduce a regular expression in the parameter Replace what and "$1 - $2" in the parameter Replace by. That should work, as far as I am concerned, but I don't obtain the expected expression but just a Text field saying "$1 - $2" literally.
What am I doing wrong? I would appretiate some help.
Thanks!
I have a collection of attributes that have values like 1 ~ 5, 5 ~ 20, and so on, and I would like to use the Map operator to map those values into something of the type 1 - 5, 5 - 20. Thus, I would like to replace the ~ symbol by the - symbol.
Anyway, like I said, I am using the Map operator to do so and, having selected my attribute, I introduce a regular expression in the parameter Replace what and "$1 - $2" in the parameter Replace by. That should work, as far as I am concerned, but I don't obtain the expected expression but just a Text field saying "$1 - $2" literally.
What am I doing wrong? I would appretiate some help.
Thanks!
0
Answers
-
Hi,
i think you need to use replace instead of map. Have a look at the attached process.
~Martin
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<process version="7.0.001">
<context>
<input/>
<output/>
<macros/>
</context>
<operator activated="true" class="process" compatibility="7.0.001" expanded="true" name="Process">
<process expanded="true">
<operator activated="true" class="generate_data_user_specification" compatibility="7.0.001" expanded="true" height="68" name="Generate Data by User Specification" width="90" x="112" y="34">
<list key="attribute_values">
<parameter key="Value" value=""1 ~ 2""/>
</list>
<list key="set_additional_roles"/>
</operator>
<operator activated="true" class="replace" compatibility="7.0.001" expanded="true" height="82" name="Replace" width="90" x="246" y="34">
<parameter key="replace_what" value="~"/>
<parameter key="replace_by" value="-"/>
</operator>
<connect from_op="Generate Data by User Specification" from_port="output" to_op="Replace" to_port="example set input"/>
<connect from_op="Replace" from_port="example set output" to_port="result 1"/>
<portSpacing port="source_input 1" spacing="0"/>
<portSpacing port="sink_result 1" spacing="0"/>
<portSpacing port="sink_result 2" spacing="0"/>
</process>
</operator>
</process>0 -
Thank you very much, Martin!
That totally worked.
I have another question that arised when I was working with the Replace operator.
Let's go back to my example: I had values of the type 1 ~ 5, 5 ~ 20. I used the operator Replace to turn those values into values of the type 1 - 5, 5 - 20. Is there any way to use those values (1 and 5, and 5 and 20, respectively) that have been captured with $1 and $2 to work with them? For example, to compute the sum of them (something of the type $1 + $2 doesn't work, it will just output a string saying 1 + 5 and 5 + 20, respectively).
Hope I expressed myself clearly!
Thank you very much in advance.0 -
Hi,
yes there is
If you use a regex like
([0-9]+).*([0-9]+)
you get the capture groups (...) as $1 and $2
Best,
Martin0 -
Hello again,
Thank you very much. That regex captured perfectly the two groups I needed for each values. Now I am trying to be able to sum the two numbers captured from the regex. But I can't because they are considered to be text and not real numbers.
Thank you!0 -
Hi,
Parse Numbers is your friend. It parses strings to numericals.
Best,
Martin0