How to Split text to newline when find some key word

i want split text to new line

this sample text

40,Mathematics,80,A,50,Adam
40,Data Structure,70,B,50,Armin
40,DataBase,80,A,50,Abigail

and i want result like this
40,Mathematics,80,A,
50,Adam
40,Data Structure,70,B,
50,Armin
40,DataBase,80,A,
50,Abigail

HI,

How about the following expression?

System.Text.RegularExpressions.Regex.Replace(yourString,"(?<=,)(?=\d+,\w+(\r?\n|$))",vbcrlf)

Regards,

1 Like

Thank you so much

1 Like

Hi Yoichi

Need help in understanding the expression, pardon my ignorance

Doubt is normally replace function should replace any character provided but in the result it is just splitting single line into 2 lines.
can you please let me know what exactly it is replacing.

Thanks inadvance

HI,

The above expression uses zero-width positive lookahead and lookbehind. So, this replaces zero-width between comma and string which is matched "\d+,\w+(\r?\n|$)" with linbreak.

Regards,

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