Using Regular Expression to find value between string and first comma

I am trying to extract data off a pdf. I’ve taken all the spaces out of the PDF to make sure there aren’t double spaces by accident. I’ve written this so far

System.Text.RegularExpressions.Regex.Match(Spaceless,“(?<=customerresidingin).+(?=,)”).ToString

In one example (unfortunately i can’t provide examples due to sensitive nature) it pulls in the correct information from the string customerresidingin until the first comma however in another example, it pulls the data until the 2nd comma. How do I correct this?

Correct:
image

image

Incorrect:
image

image

Hi, Atarantino

You can just split the string:

string.split(","c)(0)

This way, if text has comma, the expression return text before. If no, return all text in 0 index position

So simple - thank you for the quick response this was exactly what I needed.

Hello

Already solved but thought I would respond anyway :slight_smile:

Take a look at this Regex pattern:

image

Cheers

Steve

1 Like

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