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..
Asked
Active
Viewed 30 times
-1

Carlos
- 131
- 3
- 13
-
Which programming language or tool are you using? – blhsing Mar 25 '19 at 05:02
-
Have you made any attempt to solve this yourself? – glhr Mar 25 '19 at 05:57
1 Answers
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