Solved

Regex

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
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…

744 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

13 Experts available now in Live!

Get 1:1 Help Now