How to extract only first and last name from full name using regular expression

For eg,
In string i have,
String=sri g ram
I want to extract only sri and ram i.e first and last name into one string like this sri ram.
Can anyone help how to achieve this?

HI @vnsatyasunil

You can try with Split epression

Split("sri g ram"," ").first

Split("sri g ram"," ").Last

image

Regards
Gokul

1 Like

Thanks.after that how to get like this firstname lastname)i.e sri ram

HI @vnsatyasunil

Checkout the expression

System.Text.RegularExpressions.Regex.Replace(YournameString,"(?<=\S\s)\D+(?=\s\S)","")

Regards
Sudharsan

@vnsatyasunil,

You can split the name using Space and get the first and last items from the list.

FullName.Split(" "c).Last()
FullName.Split(" "c).First()

Same split expression you can try

image

Regards
Gokul

No.we got firstname and last name separately in 2 strings right.how to join first and last names in single string?like i want string=sri ram

HI @vnsatyasunil

Use Assign activity Join the string

OutputVariable = Split("sri ram"," ").first+" "+Split("sri ram"," ").last

image

Regards
Gokul

Another way @vnsatyasunil

String.Concat(Split("sri ram"," ").first+" "+Split("sri ram"," ").last)

image

You can also use this , This will get the name in the single line @vnsatyasunil

Regards
Sudharsan

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