The Altair Community is migrating to a new platform to provide a better experience for you. In preparation for the migration, the Altair Community is on read-only mode from October 28 - November 6, 2024. Technical support via cases will continue to work as is. For any urgent requests from Students/Faculty members, please submit the form linked here
MAP operator not capturing from RegEx
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!
Tagged:
0
Answers
i think you need to use replace instead of map. Have a look at the attached process.
~Martin
Dortmund, Germany
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.
yes there is
If you use a regex like
([0-9]+).*([0-9]+)
you get the capture groups (...) as $1 and $2
Best,
Martin
Dortmund, Germany
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!
Parse Numbers is your friend. It parses strings to numericals.
Best,
Martin
Dortmund, Germany