0

In Java, what is the optimum way to check if one regex satisfies another or not?

For example:

check("abc*","ab*") should return true as second regex satisfies all the patters which are satisfied by first one, where as,

check("abc*","abd*") should return false as second regex is not able to satisfy one or more patterns for first regex, i.e abcd.

Also, does Java have any inbuilt method for this?

wp78de
  • 18,207
  • 7
  • 43
  • 71
Pratik
  • 908
  • 2
  • 11
  • 34
  • 1
    I've never heard of a function like this. Are you building some sort of regex optimizer? – Calvin Taylor Jan 22 '18 at 12:02
  • for the example you gave it would be sufficient to convert both strings into actual regexes and check if the second matches the first – XtremeBaumer Jan 22 '18 at 12:03
  • @CalvinTaylor You are right Calvin, something similar to that. – Pratik Jan 22 '18 at 12:28
  • @GalAbra: Referred as duplicate question determines check 'if A intersection B is null or not', where as my question in check 'if A is subset of B or not'. Checking 'A intersection B not equals to null' also gives possibility that 'A and B are to disjoint sets', Hence it's not answer of my question. – Pratik Jan 22 '18 at 12:28
  • 3
    the first example is wrong `abc*` matches (`ab`,`abc`,`abcc`,`abccc`, etc.) whereas the second matches (`a`,`ab`,`abb`,`abbb`, etc.) maybe you are confusing regexp and glob-like pattern matching – Nahuel Fouilleul Jan 22 '18 at 13:15
  • What do you really want to do? Sounds like an [XY question](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem) to me. – wp78de Jan 22 '18 at 18:51
  • @wp78de Trying to reduce set of regEx by comparing with each other. – Pratik Jan 23 '18 at 04:11

0 Answers0