Skip to content

Instantly share code, notes, and snippets.

@h4ck4life
Created December 2, 2022 18:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save h4ck4life/8c8ce43bb471cc61bf150a69147c7b1d to your computer and use it in GitHub Desktop.
Save h4ck4life/8c8ce43bb471cc61bf150a69147c7b1d to your computer and use it in GitHub Desktop.
Example code to find multiple JSON string in a text
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Scratch {
public static void main(String[] args) {
String text = "This text contains two JSON strings: {\"key1\": \"value1\"} and {\"key2\": \"value2\"} and {\"key2\": \"value2\"}";
Pattern pattern = Pattern.compile("(\\{.*?\\})");
Matcher matcher = pattern.matcher(text);
while (matcher.find()) {
System.out.println("Found JSON string: " + matcher.group(1));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment