我有一个这样的字符串:
123456-1/1234/189928/2323 (102457921)
我想得到102457921
。如何使用正则表达式实现它?
我试过了:
"123456-1/1234/189928/2323 (102457921)".replaceAll("(\\.*\()(\d+)(\))","$2");
但它不起作用。任何提示?
答案 0 :(得分:5)
怎么样
"123456-1/1234/189928/2323 (102457921)".replaceAll(".*?\\((.*?)\\).*", "$1");
答案 1 :(得分:1)
嗯,你可以这样做:
"123456-1/1234/189928/2323 (102457921)".replaceAll(".*\((.+)\)","$1");
答案 2 :(得分:0)
你可以这样做:
"123456-1/1234/189928/2323 (102457921)".replaceAll(".*?\(([^)]+)\)","$1");
答案 3 :(得分:0)
" double" replaceAll regex简化了一个
"123456-1/1234/189928/2323 (102457921)".replaceAll(".*\\(", "").replaceAll("\\).*", "");
答案 4 :(得分:0)
你可以尝试这样的事情:
var str = '123456-1/1234/189928/2323 (102457921)';
console.log(str.replace(/[-\d\/ ]*\((\d+)\)/, "$1"));
console.log((str.split('('))[1].slice(0, -1));
console.log((str.split(/\(/))[1].replace(/(\d+)\)/, "$1"));
console.log((str.split(/\(/))[1].substr(-str.length - 1, 9));
console.log(str.substring(str.indexOf('(') + 1, str.indexOf(')')));
在其他情况下,您必须熟悉输入数据的细节才能生成合适的正则表达式。