Solved

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

Posted on 2013-11-14
3
196 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now