Solved

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

Posted on 2013-11-14
3
209 Views
Last Modified: 2013-11-20
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

0
Comment
Question by:hankknight
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 9

Expert Comment

by:Derek Jensen
ID: 39648799
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
0
 
LVL 16

Author Comment

by:hankknight
ID: 39649149
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

0
 
LVL 9

Accepted Solution

by:
Derek Jensen earned 500 total points
ID: 39649251
Now you're getting into data parsing, which can't be done with regex alone. I'm sure people much smarter than I can point you to a good text parser for CF--if you can't figure it out code-wise first.  Personally, if I were attempting this in PHP, I'd count the newlines and subdivide the block of text based on that (after exploding by newline), then implode it all back together after adding the HTML. Hope that helps. :-)
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question