[英]Get number only after last string using regex
I have been trying to implement the seperation of string into string and number in java.我一直在尝试在 java 中实现字符串到字符串和数字的分离。 As of now following pattern gives me number after string as follows:
截至目前,以下模式在字符串后给出了我的数字,如下所示:
String[] part = string.split("(?<=\\D)(?=\\d)");
Ans: "ABC123" -> ["ABC","123"]
But it fails in following scenario但它在以下情况下失败
"A1BC123" ->
expected output: ["A1BC","123"]
Kindly help请帮助
You just need two alternate for non-digit and digit.您只需要两个替代非数字和数字。 Also you need to group them separately\
您还需要将它们分别分组\
((?<=\\d)|(?=\\d))((?<=\\D)|(?=\\D))
This will separate all non-digit and digit like you said in your first paragraph, so assuming that what you want this will be the output.这将像您在第一段中所说的那样将所有非数字和数字分开,因此假设您想要的是 output。
"A1BC123" => ["A", "1", "BC", "123"]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.