Categories
Mastering Development

Make a line break when identifying (number + string)

I have the following words:

12"The world… 13The end 14"I have 16 years 15Kiss me

And I need to separate it like this:

12"The world…

13The end

14"I have 16 years

15Kiss me

To separate, I use (number + string) example (123xxx)

Any number that is concatenated with a string I need to break \n before.

I used the regex below, but it does not take into account the special symbol, and there will be several symbols in the text. And even select a number yourself

\d+\w+

enter image description here

I’m using this code in C#, and I just need to put a valid regex:

private void method()
{
    string text = "12\"The world... 13The end 14\"I have 16 years 15Kiss me";
    string ntext = Regex.Replace(text, @"\d+\w+", "\n");            
}

How can I make a regex that takes (number + string) and makes a line break?

Leave a Reply

Your email address will not be published. Required fields are marked *