How to extract matched data from any text?

Hi Everyone,
I have to extract titles like “MR, MRS, DR, MS…etc” from text like “MARIAMRS , ROBERTANDREWMR , ELENAMS”.
Please give any suggestions.

Thanks in advance

1.split your text by space
2.for each item in collection
3.if item contain MR or MRS or DR or etc
5. get the value of the item

1 Like

Hi @Suggala_Tejaswi ,

Could you provide us the input data in the form of a Text file ? Also provide us the Expected Output after the operation is performed on the data.

This way we can make the logic concrete and suggest you with an appropriate solution.

1 Like

Hi @Youssef_Ouajdi
There is no space in text

can you provide me an exemple?

1 Like

Hi @supermanPunch

I’m attaching text file here
chauffeurAek041201AUG221231Jul22212429.XML (29.2 KB)

My inputs are like MR or MRS or MISS or MS…etc

I have to split the FST tag value highlighted in attached image and my output should be DEJANMA stored in one variable and MRS should be stored in another variable

Hi,

Hope the following sample helps you.

m = System.Text.RegularExpressions.Regex.Match(currentItem.Value,"(?<FIRSTNAME>.*)(?<TITLE>MR|MS|MRS|MISS)$")

Sample20221016-1.zip (6.3 KB)

If you need to add other title, add it to regex pattern with | . For example, in case to add DR is as follows:

m = System.Text.RegularExpressions.Regex.Match(currentItem.Value,"(?<FIRSTNAME>.*)(?<TITLE>MR|MS|MRS|MISS|DR)$")

Regards,

Hi,

Hope the following sample helps you.

you only need to create two variable to get the data

Séquence.xaml (8.0 KB)

Regards

1 Like

I’m unable to opening the xaml file

Hi @Yoichi
Thank you for your solution,i have one more query how we can pass variable in regex in the place of MR ,MRS…etc?

Hi,

m = System.Text.RegularExpressions.Regex.Match(currentItem.Value,"(?<FIRSTNAME>.*)(?<TITLE>MR|MS|MRS|MISS)$")

Then

varFirstName = m.Groups("FIRSTNAME").Value
varTitle = m.Groups("TITLE").Value

Regards,

image

1 Like

Hi,

Sorry for multiple replies.

If you need to pass variable as part of regex pattern, the following will help you, for example.

arrtitle = {"MR","MS","MRS","MISS"}

Then

m = System.Text.RegularExpressions.Regex.Match(currentItem.Value,"(?<FIRSTNAME>.*)(?<TITLE>"+String.Join("|",arrTitle)+")$")

Note: this assumes there is no special character in arrTitle.

Regards,

1 Like

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