Regex to get a before value from a string

Hi Guys can you please help me to extract regex to get a value from text below?

example 1 : Carbohydrate / Glucides 11 g\r0 %\r8 % Fibre / Fibres 0 g\rSugars / Sucres 8 g
example 2 : Carbohydrate / Glucides 9 g\r14 %\r1 % Fibre / Fibres 4 g\rSugars / Sucres 1 g
Fibre - 0 in example 1 AND 14 in example 2 highlighted in bold
Sugar - 8 in example 1 and 1 in example 2 highlighted in bold,

The issue is sometimes the values can be as below so it should work for all
example 1 : Carbohydrate / Glucides 11 g\r0 %\ Fibre / Fibres 0 g
example 2 : Carbohydrate / Glucides 9 g\r1 %Sugars / Sucres 1 g

or

example 1 : Carbohydrate / Glucides 11 g\r Fibre / Fibres 0 g\rSugars / Sucres 8 g
example 2 : Carbohydrate / Glucides 9 g\r14% Fibre / Fibres 4 g\rSugars / Sucres 1 g

yes the text is retrieved from word table but the text in table is anchored correctly but when extracted digit value is coming before the actually one.

Thanks

Hi @Akshay_Suryawanshi

You can utilize the following regex patterns to extract the data despite of the changes like this:

For Sugar -

(?<=Sugars \/ Sucres )\d+(?= g)

For Fibre -

(?<=Fibre \/ Fibres )\d+(?= g)

image

Hope this helps,
Best Regards.

Hi @arjunshenoy

Thats positive lookahead text thats shown in your output,

I need to extract the digit that is before Fibre I have highlighted it in Bold.
i.e. 0 and 8 in example 1

Hi @Akshay_Suryawanshi

Here are the regular expression that should extract the values you need:

For Fibre:-
(?<=Fibre / Fibres )\d+

For Sugars-
(?<=Sugars / Sucres )\d+

It uses a positive lookbehind to find the preceding string and then matches one or more digits following it.

Thanks!!

Hi @Akshay_Suryawanshi

Greetings!

Try using the below mentioned expression in Regex Activities
(\d*)\s+g\s*(?:Fibre / Fibres)*

let us know if it helps!

Thanks