-1

It is necessary to match the string set into quotes that is followed by the world "xyz_id": For example the text is like this: "xyz_id":"55555" It's necessary to get only 55555 with a regular expression..

Carlos
  • 131
  • 3
  • 13

1 Answers1

1

Following regex will help you extract "55555":

\"xyz_id\":\"(.*)\"

https://regex101.com/r/5VnGKN/1

Below is sample code in Java:

            String x = "\"xyz_id\":\"55555\""; //String on which processing needs to be done
            Pattern pat1 = Pattern.compile("\"xyz_id\":\"(.*)\""); //Pattern to compare
            Matcher mat1 = pat1.matcher(x);       
            while(mat1.find()){
                System.out.println(mat1.group(1));
            }

Output:

55555
mukesh210
  • 2,792
  • 2
  • 19
  • 41
  • Thank you @Mukesh this line solved specifically my issue: `System.out.println(mat1.group(1));` as I did not know that I could select a group with the language used, I was looking to do it with the same regular expression and this approach had me in trouble. Then after I realized this I found a way to use it in JavaScript too with this answer:[link]https://stackoverflow.com/a/432503/3363138[/link] – Carlos Mar 26 '19 at 01:02
  • Welcome... Glad to help. Please include language tags too so that people can provide Language specific answer. – mukesh210 Mar 26 '19 at 01:05