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
finds() returns false when text contains line feed
MaxF
Member Posts: 5 Contributor II
Hi there,
I've been working a lot with regex and texts lately and come across an unexpected behaviour of the finds() expression. Whenever there is a line feed in the text, finds() without modifiers will always return false, even finds(TextAttribute,"."). Using the dotall mode, finds(TextAttribute, "(?s)."), it matches any substring of the first line but not of the following lines. So what's apparently happening in the background is that finds(TextAttribute,"(?s)expression") is translated to matches(TextAttribute,".*(?s)expression.*"). Can anyone reproduce this behaviour and can confirm that this is happening? If so, I think there is a find() method in Java that could be used to solve this problem. I don't have any experience in Java though, and there might be a reason for not using that.
So far I've simply used matches() with dotall mode instead of finds(), which works fine for me. But in case anyone can reproduce the behaviour of the finds() expression, it might be useful for others, who rely on this expression, to know about that behaviour.
Regards
Max
Max
Tagged:
1
Comments
Scott
<context>
<input/>
<output/>
<macros/>
</context>
<operator activated="true" class="process" compatibility="8.0.001" expanded="true" name="Process">
<process expanded="true">
<operator activated="true" class="text:create_document" compatibility="8.1.000" expanded="true" height="68" name="Create Document" width="90" x="246" y="136">
<parameter key="text" value="first line second line"/>
</operator>
<operator activated="true" class="text:documents_to_data" compatibility="8.1.000" expanded="true" height="82" name="Documents to Data" width="90" x="380" y="136">
<parameter key="text_attribute" value="Text"/>
</operator>
<operator activated="true" class="generate_attributes" compatibility="8.0.001" expanded="true" height="82" name="Generate Attributes" width="90" x="514" y="136">
<list key="function_descriptions">
<parameter key="FindsAnything" value="finds(Text,".*")"/>
<parameter key="FindsWithModifier1" value="finds(Text,"(?s)first")"/>
<parameter key="FindsWithModifier2" value="finds(Text,"(?s)second")"/>
</list>
</operator>
<connect from_op="Create Document" from_port="output" to_op="Documents to Data" to_port="documents 1"/>
<connect from_op="Documents to Data" from_port="example set" to_op="Generate Attributes" to_port="example set input"/>
<connect from_op="Generate Attributes" 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>
Just curious - why are you still on RM 8.0?
Scott