Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save muhdkhokhar/127a01415aa89f5df78c86f050e9e9a0 to your computer and use it in GitHub Desktop.
Save muhdkhokhar/127a01415aa89f5df78c86f050e9e9a0 to your computer and use it in GitHub Desktop.
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class PlaceholderExtractor {
public static void main(String[] args) {
String input = "abc %current_uk_time% test %another_one%";
// Extract placeholders from the input string
Set<String> placeholders = extractPlaceholders(input);
// Print extracted placeholders
System.out.println(placeholders); // Output: [current_uk_time, another_one]
}
public static Set<String> extractPlaceholders(String input) {
Set<String> placeholders = new HashSet<>();
// Pattern to match placeholders in the format %placeholder_name%
Pattern pattern = Pattern.compile("%(.*?)%");
Matcher matcher = pattern.matcher(input);
while (matcher.find()) {
// Extract the placeholder name (without the % characters)
String placeholder = matcher.group(1);
placeholders.add(placeholder);
}
return placeholders;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment