How do I get a number before a keyword in a string?

Hi, I am working with an unstructured pdf. I can get the text of a page as string. Now I need to get the number before the keyword “invoice”, e.g.: 2x invoice -> 2. The keyword is unique and there is always an “x” but I don’t have other elements to use. How would I do that best? Thanks a lot.

@Jizh You can use regular expression to get only number before “x” take a look here

1 Like

Thanks, that looks good. How can I assign it to a new string variable?
I have NumberVar=Regex.Matches(stringVar,"(\d+)x invoice") but it doesn’t work yet.

@Jizh Here you go GetNumber.xaml (7.1 KB)

1 Like

Hi @Jizh,

This might help you-

Thanks,

Thanks, I’m almost there now. The thing is that I need only the number before the word “invoice”. If the string has another number with x before it should be ignored (e.g. 3x flyer -> ignored).
Edit: @Nitesh I know that it’s similar to the thing I asked yesterday but I didn’t find a tutorial how to use it with a keyword.

I would like to have it this way: https://regex101.com/r/0KXfiG/1

@Jizh correct me if i am wrong. you needs to get only number before invoice

example afhjfaksdj 11x flyer asdfhkjdf 22x invoice sdfafs

from the above string you needs to get only 22 right know?

1 Like

Yes exactly, sorry for being unprecise.

@indra Do you know how I could do that?

Hi @Jizh
Can you for example use the workflow submitted by @indra, where you place your regex in Assign to get the string with the number followed by “x invoice”, then split the string using “x” as a separator and later take the first part of that split string (which as a result is going to be your number)?


Does it solve your problem?:slight_smile:

3 Likes

Thanks for the reply PAD.
I looked a bit further into Regex and I think I found another way if anyone is interested:
(\d+)(?=x invoice) -> this gives just the number

Yes, that’s another way to do it :slight_smile:

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