0

我有一个这样的字符串:

123456-1/1234/189928/2323 (102457921)

我想得到102457921。如何使用正则表达式实现它?

我试过了:

"123456-1/1234/189928/2323 (102457921)".replaceAll("(\\.*\()(\d+)(\))","$2");

但它不起作用。有什么提示吗?

4

5 回答 5

5

怎么样

"123456-1/1234/189928/2323 (102457921)".replaceAll(".*?\\((.*?)\\).*", "$1");
于 2014-05-02T13:29:13.273 回答
1

好吧,你可以这样做:

"123456-1/1234/189928/2323 (102457921)".replaceAll(".*\((.+)\)","$1");
于 2014-05-02T13:29:31.597 回答
0

你可以这样做:

"123456-1/1234/189928/2323 (102457921)".replaceAll(".*?\(([^)]+)\)","$1");
于 2014-05-02T13:29:45.507 回答
0

“双”replaceAll 正则表达式简化了一个怎么样

"123456-1/1234/189928/2323 (102457921)".replaceAll(".*\\(", "").replaceAll("\\).*", "");
于 2014-05-02T14:09:35.757 回答
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(')')));

在其他情况下,您必须熟悉输入数据的细节才能生成合适的正则表达式。

于 2014-05-02T16:59:59.717 回答