如何在String和两个点之间找到一些东西?

时间:2021-04-21 19:19:05

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 %

COMISION 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

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.

我是正则表达世界的新手,所以任何帮助都是值得欣赏的。

2 个解决方案

#1


2  

You can use this regex to capture your number:

您可以使用此正则表达式来捕获您的号码:

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

ReEx Demo

In your regex negative lookbehind (?<=\.\.) will assert first two dots in the input that are right after 002.

在正则表达式中,负向后观(?<= \。\。)将在输入中断言前两个点,这些点位于002之后。

#2


0  

You could use the first group of the following regex.

您可以使用以下正则表达式的第一组。

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

Demo

#1


2  

You can use this regex to capture your number:

您可以使用此正则表达式来捕获您的号码:

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

ReEx Demo

In your regex negative lookbehind (?<=\.\.) will assert first two dots in the input that are right after 002.

在正则表达式中,负向后观(?<= \。\。)将在输入中断言前两个点,这些点位于002之后。

#2


0  

You could use the first group of the following regex.

您可以使用以下正则表达式的第一组。

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

Demo