Solved

Regex

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
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…

790 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