Split a string based on Regex

To get index of first digit: YourStringVariable.IndexOfAny("0123456789".ToCharArray())

To get index of last digit: YourStringVariable.LastIndexOfAny("0123456789".ToCharArray())

@Dave i just want regex pattern to find those positions not other methods i required it for something bro

Why do you require regex in this instance? It is slower than the method I just posted.

Generally you would use regex to pull out the exact string, not to find an index.

@Dave i want to get that numbers only

example: asd12da34ds result= 1234
ashd123 result=123
asd34dsj result=34
1234dsjkd result=1234

Ok i’m a bit confused because earlier you had stated (bold=mine):

@Dave “Based on your example string “dsgjdg1234dskjk”, are you trying to get results of index=6 for first digit and index=9 for your last digit?” i want this result

Assuming whitespaces should separate out different numbers/results, then you are looking for this regex pattern: \d[\w]*\d

How it works:
\d = finds any digit.
[\w]* = finds any non white-space characters. The asterisk * matches the preceding character 0 or more times (so it finds as many non white-space characters until the next piece)
\d = finds any digit. As this is the last piece in the regex statement, it will find the last digit and the previous [\w]* will stop searching for more non white-space characters.

If you want whitespace characters returned in your match, then you should instead use \d.*\d

This works the same way as the one above, but replaces [\w]* with .* The period . matches (almost) any character. It is quite slow though, so often it is better to use a character class or negated characters instead if at all possible.

EDIT: Based on your questions above it seems like you’re using regex in your workflows a decent amount. I’d highly recommend reading up a bit on regex at https://www.regular-expressions.info/ as it is a fantastic resource. I also use .NET Regex Tester - Regex Storm to test out my .NET regex expressions and their quick reference at .NET Regex Reference - Regex Storm can come in handy as well.

Hi @Manjuts90,

Refer this post
Copy to Another excel but only the numbers - #4 by arivu96

System.Text.RegularExpressions.Regex.Replace(value1.ToString(), "[^0-9]+", string.Empty)


Hi @Manjuts90

I think the formula below will works :

System.Text.RegularExpressions.Regex.Split(varTarget,"[^0-9]+",System.Text.RegularExpressions.RegexOptions.None).Where(Function(x) x<>"").ToArray()


@arivu96 "ab"c regex returns first occurrence position of substring “ab” in String “abdshjabdjskabdjs”. i want last occurrence position of substring “ab” in above. i want regex pattern for this. Can you help me on this.

@lainh "ab"c regex returns first occurrence position of substring “ab” in String “abdshjabdjskabdjs”. i want last occurrence position of substring “ab” in above. i want regex pattern for this. can you help me on this.

Hi @Manjuts90,

From this post i dont know what do you need. Could you give some example ? And clearly mark which phrase you need to cut out ?

If you still need isolate number here you got regex: (?<Text>(?:\s)?(?:\D*))(?<Number>(?:\s)?(?:\d*)\s?)

@fudi5 In given string “sdghabeddghabuioiyabdfjsk” i want find position of last occurrence “ab” using regex.

Hi @Manjuts90

use this method in you assign activity :

[target string].ToString.LastIndexOf("ab")

And the result positon(Int32) should plus 1 .

@lainh sorry for repeatedly asking samething but i asked solution by using regex.

sorry ,I colud not get you ,because I think it can not write a single regex formula to get the last position.

I do write a xaml with only the regex.match method,but not only a single formula.
If you suppose that , I will upload it later.

I think you’ve received a ton of help and hand-holding here, it would be best for you to take some time to learn a bit on your own. If everyone simply tells you what to do and you copy+paste it into your workflow, then you won’t be learning anything and will likely get stuck on something similar to in the future. Instead of asking for someone to simply do your work for you, it is instead much better to do the following:

  1. Explain what you’re trying to achieve
  2. Give us some code or explanation of what you’ve tried already and what part isn’t working. Give exact errors if applicable

If you at least show SOME effort of trying, people will be much more likely to be helpful and you will learn much more by actually attempting to figure out some of it yourself.


In given string “sdghabeddghabuioiyabdfjsk” i want find position of last occurrence “ab” using regex.

This question doesn’t make sense. You say you want the last position - why? We’ve tried showing you the string.lastindexof(string) and you repeatedly say you don’t want that, without any explanation why. Then, you say you want the last match for a specific phrase such as “ab”. However, if you are simply searching for that exact phrase, why would it matter whether it was the last instance of that phrase? Either way, the phrase would be the same.

1 Like

@Dave i have asked just one question not many questions as you saying, May be my question was not clear.

511764.pdf (293.0 KB)

i need to get text from this pdf certificate no and etc etc but i cant extract how could i do it.please i need help from you

Please Suggest Any solution bellow scenario

Hello @ChinnapuReddy

I would check if there are any hidden characters between the words first by placing it in notepad or something and moving the cursor between the characters; like if it takes 2 cursor movements to get from “o” to “T” then there is a hidden newline character between it. If the hidden character is there then you can simply use the .Split() method.

However, that is most likely not the case, so we can explore a Regex solution.
We can split by a capital letter like this:


I am using the “?=” so it looks for A-Z but doesn’t include it, otherwise you will remove the character from the split. Also, I use .Skip(1) so it removes the first item since the “V” will add an item at the start.

As a test you can join the array in a message box:


I hope this is helpful.



Thanks for reply , i will try it and i will get back to you with my result or feed back