Removing new line in regex not working

This is the regex I used

Regex.Replace(pdf_Details_NoDate, “(?<=\d.\d{2}***)(\n\s*\n)”, “”)

Text format:

***Elov Chinese Drugstore ***
4,075.82

Four Thousand Seventy Five pesos and Eighty Two Cents only

***ATHENA JILLIAN TOBIA ABIGANIA ***
955.50

Nine Hundred Fifty Five pesos and Fifty Cents only

***Holiday Inn Galleria Manila ***
3,331.17

Three Thousand Three Hundred Thirty One pesos and Seventeen Cents only

***HOLY COW CHOPHOUSE INC.-N ***
5,501.22

Five Thousand Five Hundred One pesos and Twenty Two Cents only

***South Star Drug Inc ***
2,730.81

Two Thousand Seven Hundred Thirty pesos and Eighty One Cents only

***Amphil Lasa Foods Inc ***
8,990.25

Eight Thousand Nine Hundred Ninety pesos and Twenty Five Cents only

Expected output:

***Elov Chinese Drugstore ***
4,075.82
Four Thousand Seventy Five pesos and Eighty Two Cents only

***ATHENA JILLIAN TOBIA ABIGANIA ***
955.50
Nine Hundred Fifty Five pesos and Fifty Cents only

***Holiday Inn Galleria Manila ***
3,331.17
Three Thousand Three Hundred Thirty One pesos and Seventeen Cents only

***HOLY COW CHOPHOUSE INC.-N ***
5,501.22
Five Thousand Five Hundred One pesos and Twenty Two Cents only

***South Star Drug Inc ***
2,730.81
Two Thousand Seven Hundred Thirty pesos and Eighty One Cents only

***Amphil Lasa Foods Inc ***
8,990.25
Eight Thousand Nine Hundred Ninety pesos and Twenty Five Cents only

I wnat this so I able to convert it datatable much easier 3 columns datatable

For much clearer view

Text format:

Expected output:

@joscares

try this

System.Text.RegularExpressions.Regex.Replace(strvar,"(?<=\d*,?\d*\.\d{2}\*{3}\n)\r?\n","",System.Text.RegularExpressions.RegexOptions.MultiLine)

cheers

1 Like

Hi @joscares ,
Could you please try below and update me if you face issue.

System.Text.RegularExpressions.Regex.Replace(your text, "^\s*$", "", System.Text.RegularExpressions.RegexOptions.Multiline)
1 Like

Nothing happens after I tested this

Hi @joscares

Check the below xaml file:
Sequence.xaml (9.9 KB)

Input:
Input.txt (659 Bytes)

Output:
Output.txt (657 Bytes)

Hope it helps!!

1 Like

Document is invalid I can’t open the file

Nothing happens on this regex

Hi @joscares

Check the below zip file

BlankProcess23.zip (169.8 KB)

Hope it helps!!

1 Like

@joscares

Added one more check thsi

System.Text.RegularExpressions.Regex.Replace(strvar,"(?<=\d*,?\d*\.\d{2}\*{3}\r?\n)\r?\n","",System.Text.RegularExpressions.RegexOptions.MultiLine)

Cheers

No output when i test it

It works if I remove the 2 empty lines at start. So how can i remove the 2 empty lines at start?

@joscares

Use strvar.Trim

Cheers

It works on test workflow but when I run the actual code there’s still new line after amount

this is the variables assign

Removal of dates
pdf_Details_NoDate = System.Text.RegularExpressions.Regex.Replace(pdf_Details, “(?:January|February|March|April|May|June|July|August|September|October|November|December)\s\d{2},\s\d{4}\n?|\n”, “”)

Trim new line at start
pdf_Trimmed = pdf_Details_NoDate.TrimStart

Removal of new line after amount (Not working on actual code
pdf_Details_Final = System.Text.RegularExpressions.Regex.Replace(pdf_Trimmed,“(?<=\d*,?\d*.\d{2}*{3}\r?\n)\r?\n”,“”,System.Text.RegularExpressions.RegexOptions.MultiLine)

sample.txt (84.3 KB)

@joscares

according to the text file I made this cchange please try

System.Text.RegularExpressions.Regex.Replace(strvar,"(?<=\d*,?\d*\.\d{2}\*{3}\s{1})\s+","",System.Text.RegularExpressions.RegexOptions.MultiLine)

image

Hope this helps

cheers