Solved

Regex

Posted on 2011-02-21
4
1,169 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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Media.Imaging 1 18
Video Player 11 23
Jquery/JSON passing value from one function to another 12 38
List<PaisEntity> - show some 1 24
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…

777 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