Search code examples
javaregexscalafrej

FREJ Regex cannot match non alphanumeric characters


I've been trying to match some strings using java FREJ Regex that contains non alphanumeric characters, but the match each time returns false. Can anyone please suggest what is wrong with the following code (scala)?

import net.java.frej.Regex
val pattern = new Regex("0001-0001")
val result = pattern.`match`("0001-0001")

Solution

  • For a fuzzy library, it is not very fault tolerant. When you pass "0001-0001" into match, it tokenizes the string into "0001", "-", "0001" and runs the fuzzy search against those tokens.

    The following solution matches:

     val pat = new Regex("[0001,-,0001]")
     val res = pat.`match`("0001-0001")
    

    Or no hyphen in the match string oddly also matches.

     val pat = new Regex("0001-0001")
     val res = pat.`match`("00010001")