regex - Regular Expression with Split in VB.NET -



regex - Regular Expression with Split in VB.NET -

i want utilize split , regular expressions separate special codes in line. line:

14s15t3c16w17a0-20m0-7t

now want separate out each item, , items e.g. 14s, 15t, 7t, etc. consists of random length of digits , 1 single alphabet after digit:

e.g.: 125125125125125x or 11t.

there exception 0- , these remain are, , must separated out too.

i have made regular look myself:

dim digits() string = regex.split(line, "([0-9][a-z]|0-)")

but problem takes 1 digit of combination, example, if line 11t2b13d, separate this: 1, 1t, 2b, 1, 3d

how can solve problem?

since there single alphabet character or slash - (for case of 0-) ends each token, can split using regex.split regex:

(?<=[-a-za-z])

(?<=pattern) zero-width (text not consumed) positive look-behind, , match if text before current position matches pattern inside.

the regex above checks character before current position alphabet (upper or lower case) a-za-z or dash -, , split @ current position.

alternatively, can regex.matches regex:

[0-9]+[a-za-z]|0-

since number can arbitrary long, need 1 or more quantifier +. rest should clear, since close have tried.

both method should have same effect valid input (according specification). however, when input invalid, regex.split approach produce invalid tokens, while regex.matches approach produces valid tokens (it skip invalid character/sequences).

regex vb.net

Comments

Popular posts from this blog

javascript - mongodb won't find my schema method in nested container -

Hibernate criteria by a list of natural ids -

ios - Lagging ScrollView with UIWebview inside -