Solved

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

Posted on 2013-11-14
3
200 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 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
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…

861 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

21 Experts available now in Live!

Get 1:1 Help Now