-4

Is there a way to know which pattern was used in this case. I mean sometime i can get input like "123<=456" sometime like "123>=456". My question is, is it posible to know if "<=" was the used pattern or ">="

Pattern pattern = Pattern.compile("(<=)|(>=)");
String x= "123<=456"; \\"123>=456"
String[] t = pattern.split(x);

1 Answers1

2

A better way to parse the input

Using this:

([0-9]+)(>=|<=)([0-9]+)

Regex101

You can parse 123<=456 into:

  • 123
  • <=
  • 456

and 123>=456 into:

  • 123
  • >=
  • 456
jrtapsell
  • 6,719
  • 1
  • 26
  • 49