Regex count spaces after a comma (if there is one)

hi all,

i am working on a project where i am using regex to extract data from text files and then writing that value to a datatable

i can work with the data if there is no comma, or if there are 2 or more digits after the comma

i have an issue though if the data i am extracting has only one digit after a comma

image
the value is coming out as 1273 but it should be 1273.5

ideally i would like to count the number of comma’s (if any) in the string and then write a switch based on what should happen then
no comma eg 123 report 123
1 comma eg 321.6 report 321.6 or 321.60 just not 321 as is currently being reported
2 or more commas eg 568.8765432 report 568.87

the work flow is attached, along with a few text files that i used as well

any help greatly appreciated
Main.xaml (27.1 KB)

Text file 3.txt (31 Bytes)
Text file 4.txt (80 Bytes)
Text file 5.txt (75 Bytes)
Text file 1.txt (72 Bytes)
Text file 2.txt (73 Bytes)

Just write a RegEx expression that takes only digits and comma.

^[-,0-9]+$

.net - Matching numbers with regular expressions — only digits and commas - Stack Overflow.

It looks like the value parsing of number in French close culture is needed
e.g. Valeur Liquidative (VL) : 1 273,5 ( USD) as space is used as a group seperator

in general we can do it by
grafik

And can also reformat e.g. like
grafik

For catching the number we can use Regex and also extend it. Just a starter partern focussing on French Formats

grafik
\d[\d ]*[,\d]*
For sure we can tune and adapt the pattern

Will give that a try and get back to you.

Thanks

in certain scenarios we were also able to reduce the complexity by removing spaces then we can reduce the complexity of the regex to

grafik
and parse like
grafik

Hey @adrian_sullivan

Take a look here:
AS-19.01.24.zip (15.5 KB)
image

Results
image

Regex Pattern used:

image

Note results added to table have spaces removed and commas replaced with .

Hopefully this helps,

Cheers

Steve

1 Like

Hi @adrian_sullivan

Check out the below workflow file:
Sequence22.xaml (13.6 KB)
Workflow:

Output:

Happy to help if further clarifications needed.

Regards

hi Steve,

thanks fo the help. tried this and it worked ok. i did have to make one minor change. i had to add an if statment to see if a value was left blank. if it was blank i put in a value like N\A just so as it would be reported on.

Adrian

Hey

Oops, I missed the blank values.

Great to hear you have a working solution.

Cheers

Steve