Search code examples
regexnsregularexpressionqregularexpressionstring-operations

Compare two substrings separated by a /


Goal Compare two substrings separated by a /:

  • If the substrings are the same, hide the entire string.
  • If the substrings are different, display only the part after the /.
  • The string will contain characters like _ and - in addition to numbers and letters.

Original String Structure: text1/text2

Rules

  1. If text1 == text2:
    Output: No text (hide everything).
  2. If text1 != text2:
    Output: Only text2.

Examples

Input: ABC-ABC/ABC-ABC
Since text1 == text2, the output is empty.
Input: ABC-ABC/DEF-DEF
Since text1 != text2, the output is DEF-DEF.

I have tried this ((\w+)(?=\/\2)), however, it has the opposite logic of what I need. This wil work in my program: https://regex101.com/r/jMqT0Z/1

I thought this should work ^([^\/]+)\/(?:\1$\r?\n?)?; the logic is right according to regex101. But it will not work/run in my program. https://regex101.com/r/cLTHNZ/1

References:

The program that the regex will run on is EPLAN: https://www.eplan.help/ko-kr/Infoportal/Content/EECPro/2.8/EPLAN_Help.htm#htm/refregex_r_regular_expressions.htm

The sources/rules should be these: https://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html https://docs.oracle.com/javase/tutorial/essential/regex/


Solution

  • In EPLAN, there is a prefix/syntax that needs to be correct. This is what it looks like in the program: ○│??_??@^([^\/]+)\/(?:\1$\r?\n?)?;│