Solved

Regex

Posted on 2011-02-21
4
1,172 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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…

705 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