Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 从文本文件中提取数据-重复值_Java_Regex_Extraction - Fatal编程技术网

Java 从文本文件中提取数据-重复值

Java 从文本文件中提取数据-重复值,java,regex,extraction,Java,Regex,Extraction,790009!017009!0479%0009!0479 0009!0469%0009!0469 0009!0459%0009!0459'009 0009!0459%0009!0449 0009!0449%0009!0449 0009!0439%0009!0439 0009!0429%0009!0429'009 0009!0429%0009!0419 0009!0419%0009!0409 000'009!0399 0009!0389%0009!0389'009 0009!0379%0009!0

790009!017009!0479%0009!0479 0009!0469%0009!0469 0009!0459%0009!0459'009 0009!0459%0009!0449 0009!0449%0009!0449 0009!0439%0009!0439 0009!0429%0009!0429'009 0009!0429%0009!0419 0009!0419%0009!0409 000'009!0399 0009!0389%0009!0389'009 0009!0379%0009!0369 0009!0349%0009!0349 0009!0339%0009!0339 0009!0339%0009!0329'009 0009!0329%0009!0329 0009!032

在这个数据中,我应该提取数字47,46,45,44等等。我应该避开其余的。数字始终遵循此流程-9!0不超过9% 例如:9!0 42 9% 我应该用哪种语言来解决这个问题,哪种函数可以帮助我? 是否有任何函数可以定位一个特殊字符并复制接下来的两个或三个元素? 例:9!0.42 9%和'009
小心!然后从那里复制42,注意引用另一个值009的'。这就像使用两个不同的正则表达式。

您可以使用任何您想要的语言,甚至可以使用诸如sed、awk或grep之类的unix命令行实用程序。正则表达式应该是这样的-你想要匹配9!0后面跟数字,后面跟0%。使用这个正则表达式:9!0\d+0%或如果数字都是两位数,则为9!0\d{2}0%。

这是perl:

@result = $subject =~ m/(?<=9!0)\d+(?=9%)/g;
它将为您提供一个包含所有数字的数组。你没有提供语言,所以我不知道这是否适合你

Pattern regex = Pattern.compile("(?<=9!0)\\d+(?=9%)");
Matcher regexMatcher = regex.matcher(subjectString);
while (regexMatcher.find()) {
    // matched text: regexMatcher.group()
    // match start: regexMatcher.start()
    // match end: regexMatcher.end()
} 

其他答案很好,我的正则表达式解决方案就是9\d\d

这里是powershell中的完整解决方案,可以轻松地与其他.net语言关联

$t="79 0009!017009!0479%0009!0479 0009!0469%0009!0469 0009!0459%0009!0459'009 0009!0459%0009!0449 0009!0449%0009!0449 0009!0439%0009!0439 0009!0429%0009!0429'009 0009!0429%0009!0419 0009!0419%0009!0409 000'009!0399 0009!0389%0009!0389'009 0009!0379%0009!0369 0009!0349%0009!0349 0009!0339%0009!0339 0009!0339%0009!0329'009 0009!0329%0009!0329 0009!032"
$p="9!.(\d\d)"
$ms=[regex]::match($t,$p)
while ($ms.Success) {write-host $ms.groups[1].value;$ms=$ms.NextMatch()}

Java非常受欢迎