I have tried to fix this for a long time, and i just can\'t do it.
It could be any string, but this is an example:
\"\\This string \\contains some\\ bac
It seems you just want to check if a string matches a regex pattern partially, namely, if it contains a literal backslash not preceded nor followed with a backslash.
Use
(?
See the regex demo.
Sample Scala code:
val s = """"\This string\\ \contains some\ backslashes\""""
val rx = """(? true
case _ => false
}
println(ismatch)
See the Scala online demo.
Note:
"""(? - this line declares a regex object and makes the pattern unanchored, so that no full string match is no longer required by the match blockmatch, we use case rx(_*) as there is no capturing group defined inside the pattern itself\\) that is not preceded with a backslash ((?) and is not followed with a backslash ((?!\\)).