Split a string into middle of it

Hi, I want to split the following string
“His name is Jack according to the record hi id is 789542 he is a local person”
and only need “789542” as a result. How can it be possible.

@Sheraz_Ali1 - Asssuming “id is” always present in your text…

  StrID = system.text.regularexpressions.regex.match(YourText,"(?<=id is\s+)\d+", regexoptions.ignorecase).value

Hope this helps…

But id is not always there only there is a paragraph containing digits sometimes there are 7 and sometimes 12 digits.

Thank you :grinning:

Hi @Sheraz_Ali1

Use this regx to extarct numeric from string.
txt = “His name is Jack according to the record hi id is 789542 he is a local person”

System.Text.RegularExpressions.Regex.Replace(txt,"\D","")

Thanks,
Manjula

@Sheraz_Ali1 - Then just do \d+

I tried and found this error


Help me.

@Sheraz_Ali1 , Try arr1(3).ToString

What is the variable type you set for account_a? It should be string type.

It’s an array

Thank you :partying_face: It works after converting to string.

And if there is some other numbers like
His name is Jack according to the 224 record hi id is 789542 he is a local person 12 demax.
but i need only 789542

Are these are min 6 digits to max 12??

yes in this case but may vary for other cases

@Sheraz_Ali1 - if its min 6 to Max 12, you can try the below pattern…

we can build more solid pattern if you provide more samples…

1 Like

Thank you for the help there is another case now what can I do
if there is a $ in the value like
His name is Jack according to the record he own is &789 he is a local person
what will be the change in this expression as it’s most suitable as i used it
System.Text.RegularExpressions.Regex.Replace(txt,"\D","")

@Sheraz_Ali1 - what is the output you are looking for ?

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