-4

I am having an String like this

"ATS0657882\nPRX1686559\n name: something,hello"

Now i want to do is only get the "ATS0657882","PRX1686559", and so on,

How can i do this, i used lot of ways but i cant find the solution.

  • 2
    *i used lot of ways but i cant find the solution* - please share them with us. Also don't forget to tell us what didn't work with these solutions and include any error with the full stack trace. – BackSlash Mar 07 '19 at 07:29
  • Possible duplicate of [How to split a string in Java](https://stackoverflow.com/questions/3481828/how-to-split-a-string-in-java) – Rohit5k2 Mar 07 '19 at 07:30
  • https://stackoverflow.com/questions/5582142/splitting-a-string-using-regex-in-java – Rohit5k2 Mar 07 '19 at 07:32
  • @Rohit5k2 i searched but i cant find so if u could please add some example – Mohanraj Archunan Mar 07 '19 at 07:37
  • i tried all stack overflow example for more than 1 hour – Mohanraj Archunan Mar 07 '19 at 07:37
  • Your question headline and description doesn't match. Do you want to split by "\n" or get all the string which has three characters followed by 7 digits? – Rohit5k2 Mar 07 '19 at 07:39
  • not need to get only "PRX1686559" patterns it output – Mohanraj Archunan Mar 07 '19 at 07:48
  • @Rohit5k2 /n not matters – Mohanraj Archunan Mar 07 '19 at 07:49
  • A regular expression like `[A-Z]{3}\\d{7}`? Matcher, find, group. It’s described in a lot of places, so just search for the details. You may want to require a word boundary before and after, search for that too. – Ole V.V. Mar 07 '19 at 07:54
  • your title says `Want to print string contains 3 letters followed by 7 digits`? And you're asking how to split a string? you may read this guideline - https://stackoverflow.com/help/how-to-ask – Van_Cleff Mar 07 '19 at 07:54
  • @user8478480 You may want to tell us whether you mean the question or the comments, and maybe even suggest an improvement? :-) – Ole V.V. Mar 07 '19 at 10:49

1 Answers1

0

Try this

String example = "ATS0657882\nPRX1686559\n name: something,hello";
Pattern p = Pattern.compile("[A-Z]{3}[0-9]{7}"); // or [A-Z]{3}\\d{7}
Matcher m = p.matcher(example);

while (m.find()) {
    Log.i("Findings", "values are " + m.group());
}
Rohit5k2
  • 17,948
  • 8
  • 45
  • 57