Input String = “(1) Bene Name : Adam \r\n(1) Total payee share : ₹5000 \r\n(1) Bene Address line 1: James street \r\n(1) Bene Address line 2 : New jersey”
I need to get the name “Adam” using Regex.
if I use the below Regex pattern,
Bene Name\s*:\s*([^\r\n]+) . It gets me all the sections of the string that is after "Bene Name: "
But I need only “Adam”
If I intentionally make the pattern like below,
Bene Name\s*:\s*([^(]+)
It gets me the right value, I.e. “Adam \r\n” - Values after colon and before “(”
\r\n are carriage return and new line feed characters itseems. So, Regex isn’t working in this case. So How to get the exact value.
I need to get Bene Name and Total Payee Share value from the above string. String manipulation was lengthy and that’s why thought of using Regex.
Thanks @pradeep931 . It worked.
But for Total payee share\s*:\s*₹?(\d+) , I had to use $ symbol in the string value (i.e. $5000). Replacing ₹ with $ didn’t work. So, I want to exclude the $ and get only the amount (5000)
Some alternative solutions for your review
Bene Name - preview the pattern here:
Use in an assign like to trim the spaces
System.Text.RegularExpressions.Regex.Match(yourStr, “(?<=Bene Name\s+:)[^\]+”).ToString.Trim