Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to split string into numerics and alphabets using Regex

Tags:

c#

regex

I want to split a string like "001A" into "001" and "A"

like image 632
user99322 Avatar asked Nov 23 '25 15:11

user99322


2 Answers

string[] data = Regex.Split("001A", "([A-Z])");
data[0] -> "001"
data[1] -> "A"
like image 125
James Avatar answered Nov 26 '25 03:11

James


Match match = Regex.Match(s, @"^(\d+)(.+)$");
string numeral = match.Groups[1].Value;
string tail = match.Groups[2].Value;
like image 29
Kobi Avatar answered Nov 26 '25 04:11

Kobi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!