Created
December 2, 2022 18:21
-
-
Save h4ck4life/8c8ce43bb471cc61bf150a69147c7b1d to your computer and use it in GitHub Desktop.
Example code to find multiple JSON string in a text
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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