Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2013-11-14
3
Medium Priority
?
218 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
  • 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 2000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…
Suggested Courses
Course of the Month21 days, 5 hours left to enroll

810 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