Vorenus CoA Vorenus CoA - 4 months ago 9
Java Question

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 %

I would like to get: 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"

I´m new in the regex world so any help is appreciate.

Answer

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.

Comments