简体   繁体   English

如何在字符串和两个点之间找到东西?

[英]How to find something between a String and two dots?

I´m trying to get out some value inside a text with regex. 我正试图从正则表达式的文本中获取一些价值。

Text example: 文字范例:

COMISION 002...................50.00........15.060000...............753.00 IVA 21 % 委员会002 ................... 50.00 ........ 15.060000 ...... 753.00 IVA 21%

I would like to get: 753.00 我想要得到:753.00

I´m using this regex: 我正在使用此正则表达式:

Pattern pattern = Pattern.compile("(?<=\\.\\.)(.*)(?=IVA 21 %)");

The problem is that this regex is outputting: 问题是此正则表达式正在输出:

.................50.00........15.060000...............753.00 ................. 50.00 ........ 15.060000 ............... 753.00

So I assume that the first time the engine finds the two dots (..) sets a limit. 因此,我假设引擎首次发现两个点(..)会设置一个限制。

What I want and can´t resolve is something like: "find the words "IVA 21 %", then look back and bring me all of the data till you see two dots together" 我要解决的问题是:“找到“ IVA 21%”,然后回头带给我所有数据,直到一起看到两个点”

I´m new in the regex world so any help is appreciate. 我是regex世界中的新人,因此对您的帮助是不胜感激的。

You can use this regex to capture your number: 您可以使用此正则表达式捕获您的电话号码:

\\d+(?:\\.\\d+)?(?= IVA 21 %)

ReEx Demo ReEx演示

In your regex negative lookbehind (?<=\\.\\.) will assert first two dots in the input that are right after 002 . 在您的正则表达式中,负向后看(?<=\\.\\.)将断言输入中紧接在002之后的前两个点。

You could use the first group of the following regex. 您可以使用以下正则表达式的第一组。

(\d+.\d+) IVA 21 %

Demo 演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM