Extract specific text after character "-"

Hello,
I am trying to use regex to extract specific text after -.the text is;
[EXTERNAL]Ahadi Term Assurance –Full Name I need to only extract the word ‘Full Name’

kindly assist

If it’s always going to be after the - then use Split.

myVar = “[EXTERNAL]Ahadi Term Assurance –Full Name”

myText = myVar.Split("-"c)(1)

Split gives you an array, so the first element (index 0) will be the text before the - and the second element (index 1) will be the text after.

2 Likes

@Lydia_Gathoni
Welcome to the forum

grafik
(?<=\–|\-).*

as you see we do have different types of hyphens

1 Like

Hi @Lydia_Gathoni

You can also try with Split expression

Split("[EXTERNAL]Ahadi Term Assurance –Full Name","–")(1)

image

Regex Expression

System.Text.regularExpressions.Regex.Match(YourString,"(?<=\–)(\S.+)").Tostring

image

Regards
Gokul

Thank you so much. This works

Thank you, this expression works too

Try using Substring & Index

theText.Substring(theText.LastIndexOf("–") + 1)

This will just return the Details after the Dash - so you may want to add a Trim too

1 Like

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