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
"[SOLVED] regex processing bug?"
tennenrishin
Member Posts: 177 Contributor II
Why would the following process output 'a/b/c' rather than just 'c'?
<?xml version="1.0" encoding="UTF-8" standalone="no"?>Am I missing something obvious or might this be a bug?
<process version="5.2.008">
<context>
<input/>
<output/>
<macros/>
</context>
<operator activated="true" class="process" compatibility="5.2.008" expanded="true" name="Process">
<process expanded="true" height="659" width="1042">
<operator activated="true" class="set_macro" compatibility="5.2.008" expanded="true" height="76" name="Set Macro" width="90" x="45" y="75">
<parameter key="macro" value="path"/>
<parameter key="value" value="a/b/c"/>
</operator>
<operator activated="true" class="generate_macro" compatibility="5.2.008" expanded="true" height="76" name="Generate Macro" width="90" x="179" y="75">
<list key="function_descriptions">
<parameter key="path_ending" value="replaceAll("%{path}","^.*/(?=[^/]+^)","")"/>
</list>
</operator>
<operator activated="true" class="print_to_console" compatibility="5.2.008" expanded="true" height="76" name="Print to Console" width="90" x="313" y="75">
<parameter key="log_value" value="OUTPUT: %{path_ending}"/>
</operator>
<connect from_op="Set Macro" from_port="through 1" to_op="Generate Macro" to_port="through 1"/>
<connect from_op="Generate Macro" from_port="through 1" to_op="Print to Console" to_port="through 1"/>
<portSpacing port="source_input 1" spacing="0"/>
<portSpacing port="sink_result 1" spacing="0"/>
</process>
</operator>
</process>
Tagged:
0
Answers
I think that you are missing two things, '[' and ']', and that this is not a bug. Check this out.. Best wishes,
H
Thank you for your response, but I don't understand. regexpal.com agrees that ^.*/(?=[^/]+^) matches the a/b/ in a/b/c
So I would expect the output in the OP to be c rather than a/b/c
Can you explain why you hold that a/b/c is the correct output?
Thanks
Isak
Regex formulae may not uniquely satisfy, different methods can also work; on your problem you can achieve a/b/c -> c with a regex match of [/ab], which makes a list of matchable characters, like this..
cf. http://www.lunametrics.com/blog/2006/10/22/regular-expressions-part-viii-square-brackets-and-dashes/
Best
H
PS I'm a great fan of RegexBuddy, which I think is related to the source you used; it has an explain feature - you put in your regex, and out comes an interpretation. Here's what it said about your first.. and here's what it said about my second..
a/b/c was just an example string that I happened to use, but it could just as well have been
i/know/what/my/regex/does in which case I want a match on i/know/what/my/regex/
But thanks anyway for discussing because typing out these responses revealed a typo in my regex. The regex of my intention was
^.*/(?=[^/]+$) rather than ^.*/(?=[^/]+^)
Now it all works.