Solved

Regex

Posted on 2011-02-21
4
1,168 Views
Last Modified: 2012-05-11
Hi Experts,

I need to write a regular expression that detects markup. Can anyone advise how to write an expression that can find and replace the following:

**this is a bold paragraph** with <b>this is a bold paragraph</b>
or
_this is an italic paragraph_ with <em>this is an italic paragraph</em>
0
Comment
Question by:critto
  • 2
  • 2
4 Comments
 
LVL 35

Accepted Solution

by:
Terry Woods earned 500 total points
ID: 34947846
1. Replace:
@"\*\*(.*?)\*\*"
with <b>$1</b>

2. Replace:
@"_(.*?)_"
with <em>$1</em>
0
 

Author Comment

by:critto
ID: 34947945
As in:

string pattern = "@"\*\*(.*?)\*\*";
string replacement = "<b>$1</b>";
Regex rgx = new Regex(pattern);
string result = rgx.Replace(input, replacement);

string pattern = "@"_(.*?)_";
string replacement = "<em>$1</em>";
Regex rgx = new Regex(pattern);
string result = rgx.Replace(input, replacement);

???
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 34947965
That's right
0
 

Author Closing Comment

by:critto
ID: 34948083
Thanks mate.
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…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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…

932 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

10 Experts available now in Live!

Get 1:1 Help Now