[英]Need to extract number from a string using regex expressions(without using string methods) in java [on hold]
將我的輸入字符串視為“位置 1 的員工 736213”
Output 需要:736213
您可以使用正則表達式\d{2,}
盡可能多地匹配 2 次和無限次之間的數字( [0-9]
)。 例如在 Java 中:
final Pattern pattern = Pattern.compile("\\d{2,}");
final Matcher matcher = pattern.matcher("Employee 736213 at Location1");
if (matcher.find()) {
System.out.println("Full match: " + matcher.group(0));
}
有用的鏈接: regex101和Learn regex the easy way
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.