How to see string value of a Regex which was split and in Array of String Format

Hi all, I am currently dealing with a pdf file of an invoice. I have converted the file to a text file to extract the values easier. I used regex to pull out the output below. The output is in a string format. I want to get the numbers of the postal code only from this regex output. However, when I use strVar.ToString.Split("COUNTRY ",ToCharArray) an error says that (1-dimensional array of String cannot be converted to String). I changed the output variable format to an array of string but I can’t see the output. It just give me System.String. How do I see the output and is Array of String format really necessary?

image

Hi @anonymous3
use this regex to extract the value
(?<=COUNTRY)[\d]+

Regards,
Nived N
Happy Automation

Hi @NIVED_NAMBIAR ,

I typed in System.Text.RegularExpressions.Regex.Match(strVar,"(?<=COUNTRY)[\d]+).Value
But my output was empty.

Regards,
non

Hi @anonymous3
can u share the string ?

Hi @NIVED_NAMBIAR ,
The string is the same as the sample I provided above. It is a part of confidential data so I can’t share the text file.

Hi @anonymous3
can u try this
System.Text.RegularExpressions.Regex.Match(strVar,"(?<=COUNTRY[\s]+)[\d]+").Value

Hi @NIVED_NAMBIAR
It worked! Thank you so much. Also I have one more question. Is there a way to read the COUNTRY regardless or whether it is uppercase, lowercase or mixed? For example if the string I provided above was Country or country instead, the code should still be able to read it.

Hi @anonymous3

Try this

System.Text.RegularExpressions.Regex.Match(strVar,"(?<=COUNTRY[\s]+)[\d]+",System.Text.RegularExpressions.RegexOptions.IgnoreCase).Value

Hi, @NIVED_NAMBIAR

It works thanks!!

Regards,
non

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.