[Solved] regex to find variables surrounded by % in a string
I believe you are looking for a regex pattern (?<!%%)(?<=%)\w+(?=%)(?!%%) That would find variables that are surrounded by a single % character on each side. Test the regex here. Java code: final Pattern pattern = Pattern.compile(“(?<!%%)(?<=%)\\w+(?=%)(?!%%)”); final Matcher matcher = pattern.matcher(input); while (matcher.find()) { System.out.println(matcher.group(0)); } Test the Java code here. UPDATE: If you want … Read more