-3

i want to split a string if it contains one of the following operators ==, >, <, >=, <=, !=

  1. if string equals a>b, result is [a,b]
  2. if string equals a < b, result is [a,b]
  3. if string equals a>=b, result is [a,b]
  4. if string equals a<=b, result is [a,b]
  5. if string equals a==b, result is [a,b]
  6. if string equals a!=b, result is [a,b]
Lokesh Reddy
  • 85
  • 1
  • 11
  • Please post your code – Linus Oleander Feb 25 '16 at 07:17
  • While we are willing to help you with your problem, could you please edit your question to contain a [Minimal, Complete, and Verifiable](//stackoverflow.com/help/mcve) example? We require this for debugging questions because 1) this makes it a lot easier for us to fiddle around on the actual problem, and 2) will, if solved, add to the knowledge base of Stack Overflow, so that other people with the same problem can find a solution here or learn from it. – StudioTime Feb 25 '16 at 07:19
  • 1
    And what is `<==` operator? – Tushar Feb 25 '16 at 07:19
  • Possible duplicate of [How do I split a string with multiple separators in javascript?](http://stackoverflow.com/questions/650022/how-do-i-split-a-string-with-multiple-separators-in-javascript) – Mikhail Tulubaev Feb 25 '16 at 07:23
  • `.split()` takes an optional regex as an argument. It seems you should have at least researched that and taken a shot at building the regex. – jfriend00 Feb 25 '16 at 07:32

1 Answers1

4

if you mean you have a string like a<=b and you want to split it based on the operator, a quick regex for that is:

'a!=b'.split(/==|<|>|<=|>=|\!=/) # ["a", "b"]
‌‌R‌‌‌.
  • 2,818
  • 26
  • 37