Extract a chain of character

Hi everybody,

I need to extract a chain of character of a string.

For example this one : “LA SUPPLEMENTAIRE )LM RS RENTE PF161256980000-1589656-MARIE MADELEINE 20220401 LA MON”

I need to extract only the word which begin by “PF” + 8 digits.
In this case the output string must be “PF16125698”

Any idea please ?
Thank you

Hi @guillaume.cabanes2 ,

Could you try using the below Expression :

System.Text.RegularExpressions.Regex.Match(yourInputVar,"PF\d{8}").Value

Hey @guillaume.cabanes2 ,

You can use the below code

System.Text.RegularExpressions.Regex.Match(“LA SUPPLEMENTAIRE )LM RS RENTE PF161256980000-1589656-MARIE MADELEINE 20220401 LA MON”,“PF\d{8}”).Value

Thanks,
Sanjit

1 Like

Hi @guillaume.cabanes2

What about the following?
image

Regex.Match(strValue, "PF\d{8}").Value

image

Regards

Thank you so much both of them works well :slight_smile:

Do you have an idea of how can i make sure that the 8 following characters (After “PF”) are digits please ?

Thank you

The “\d{8}” part of the Regex Provided before, is making sure that the pattern only returns something, if there are exactly 8 digits. If there are more, you can enhance it with \b at the end:

Regex.Match(strValue, “PF\d{8}\b”).Value

Exactly 8 digits:
image

Not matching if +8 digits (or -)
image

if instead of \d, you had \w, then you could have letters on it.

1 Like

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