1

I need to separate comparison operators (==, !=, >, <, >=, <=) from the string value.

I can have following possible combinations

== 1
== 100.24
== 120/numberOfRows
<= 1/3
>= 2232

I tried below regex pattern but it not working as expected.

    Pattern = "(<[=>]?|==|=<|=>|>=?|\\&\\&|\\|\\|) (\\w*\\.?\\w+\\.?\\/?\\w+)".r 
3
  • 1
    Why not just """(<[=>]?|=[<>=]|>=?|!=|&&|\|\|)\s+(.+)""".r? Commented Nov 15, 2020 at 2:30
  • Please show sample input and expected output Commented Nov 15, 2020 at 2:31
  • What's the story here? Who are you writing to and why use the deleted answer (below) as your channel of communication? Commented Apr 6, 2021 at 18:39

1 Answer 1

2

You can use

"""(<[=>]?|=[<>=]|>=?|!=|&&|\|\|)\s+(.+)""".r

See the regex demo. Details:

  • (<[=>]?|=[<>=]|>=?|!=|&&|\|\|) - <, <=, <>, =<, =<, =>, ==, >, >=, !=, && or ||
  • \s+ - 1+ whitespaces
  • (.+) - Group 2: any one or more chars, other than line break chars, as many as possible.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.