0

I need a regex which will match whitespace chars under some condition. Let's say I have this string:

String s = "{ <class body declarations> }";

I want to apply Java replaceAll method only on the whitespaces between the two delimiters < and >, to obtain this string:

"{ <classbodydeclarations> }";

Is there a regex to do that?

GioAgu
  • 59
  • 6
  • Please take a look on that post https://stackoverflow.com/questions/7124778/how-to-match-anything-up-until-this-sequence-of-characters-in-a-regular-expres – Niv Nov 26 '18 at 23:51

1 Answers1

0

the following regex works, however it can be tricked by an unexpected <. see https://regex101.com/r/nBm213/2 for a demonstration.

(?:(?<=<).*?)( )(?:.*?(?=>))

feel free to improve on this answer.

MCO
  • 1,187
  • 1
  • 11
  • 20