Link to home
Start Free TrialLog in
Avatar of hankknight
hankknightFlag for Canada

asked on

ASP.NET/VB/REGEX: Decive content in half by lines

Using ASP.NET/VB and Regular Expressions, how can I turn this:
1
2
3
4
5
a
b
c
d
e

Open in new window

Into this:
<span class="cols">
<span class="col1">
1
2
3
4
5
</span>
<span class="col2">
a
b
c
d
e
</span>
</span>

Open in new window

I want the content to be devided in exactly half.
input = RegularExpressions.Regex.Replace(input, ???, "<span class=""cols""><span class=""col1"">$1</span><span class=""col2"">$2</span></span>")

Open in new window

Avatar of Derek Jensen
Derek Jensen
Flag of United States of America image

Not sure of the translation to VB, but this regex worked for me in PHP:

/^(([0-9]|\r|\n)+?)(?<!\w)(([a-z]|\r|\n)+?)$/s

Open in new window

See it in action
Avatar of hankknight

ASKER

Thanks, I should have made my example better reflect my need.   The first half of lines should go in the first group and the second half of lines should go in the second group.  In the wild this will be more complicated than just numbers and letters.

This should be in the first group.
1st group is where this line should be.
"Line 3" should be in the first group
Line 4 belongs in the second group
This line should be in group 2
This last line goes in group two.

Open in new window

should become:
<span class="cols">
<span class="col1">
This should be in the first group.
1st group is where this line should be.
"Line 3" should be in the first group
</span>
<span class="col2">
Line 4 belongs in the second group
This line should be in group 2
This last line goes in group two.
</span>
</span>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Derek Jensen
Derek Jensen
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial