Solved

ASP.NET / VB / REGEX: Automatically Make Headings Bold Including First Line

Posted on 2012-04-01
1
483 Views
Last Modified: 2012-04-01
I use the following ASP.NET VB REGEX to automatically make headings bold.

The problem is that the first heading is not made bold because it does not begin with a new line.

This should only require a new line to work AFTER the first line.

' Thanks, kaufmed
input = "Bold Heading One" + VbNewLine + VbNewLine + "This is a test and only a test.  The heading above should be bold." + VbNewLine +VbNewLine + "Heading 2 Should be Bold" + VbNewLine +VbNewLine + "The heading above should be bold.  If it had ended with a question mark or a period or a comma or a hyphen it should not have been bold." + VbNewLine +VbNewLine + "Bold Heading" + VbNewLine + VbNewLine + "The heading above should be bold. "
input = RegularExpressions.Regex.Replace(input, "(\n)(?=.{1,100}\n)([A-Z][a-z]*(?:(?: [a-zA-Z0-9]+)* [A-Z][a-z]*)?)(\r\n\r\n)", "$1<strong>$2</strong>$3")
input = RegularExpressions.Regex.Replace(input, VbNewLine + "- ", VbNewLine + "&#8226; ")
input = RegularExpressions.Regex.Replace(input, VbNewLine, VbNewLine +"<br />")
return input

Open in new window

0
Comment
Question by:hankknight
1 Comment
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 37793395
Change the first part of the pattern to:

(^|\n)
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

746 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

9 Experts available now in Live!

Get 1:1 Help Now