-1

I've got the following code

String valuepairName = "sc_mpl_MAX_AUD_TIME_To_20_Val.$$DATE_TO_LOAD";
boolean result = valuepairName.matches("sc_mpl_MAX_AUD_TIME_To_(20|32|82)_Val.$$DATE_TO_LOAD");

The result evaluates to false, but I cannot see the mistake. This must be very trivial, hence it's driving me crazy :(

VLAZ
  • 26,331
  • 9
  • 49
  • 67
4Kings
  • 109
  • 1
  • 9

1 Answers1

4

You need to escape each $ individually (or use pattern.quote) ($ is a special character in regex). Use

boolean result = valuepairName.matches("sc_mpl_MAX_AUD_TIME_To_(20|32|82)_Val.\\$\\$DATE_TO_LOAD");

TheLostMind
  • 35,966
  • 12
  • 68
  • 104