regex question

B

Bob Weiner

I have a string which contains html tags and data. What regex patter will
capture the data without the tags?

For example
My new <a href="myHouse.com">home</a> is <B>very</B> nice!

should return:
My new
home
is
very nice!

Can this be done?

bob
 
K

Kevin Spencer

Hi bob,

The following 2 Regular Expressions both do the opposite of what you want.
It matches all substrings which begin with '<' and and with '>'. Therefore,
if you use it with Regex.Replace, and replace it with empty strings, it will
return the stripped content.

(?![^<]*)<[^>]*?>

<(?:.|\n)+?>

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.
 
B

Bob Weiner

Thanks!

I'm going to have to play with them to understand.

bob


Kevin Spencer said:
Hi bob,

The following 2 Regular Expressions both do the opposite of what you want.
It matches all substrings which begin with '<' and and with '>'.
Therefore, if you use it with Regex.Replace, and replace it with empty
strings, it will return the stripped content.

(?![^<]*)<[^>]*?>

<(?:.|\n)+?>

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.

Bob Weiner said:
I have a string which contains html tags and data. What regex patter will
capture the data without the tags?

For example
My new <a href="myHouse.com">home</a> is <B>very</B> nice!

should return:
My new
home
is
very nice!

Can this be done?

bob
 
J

jeremiah johnson

String before =
"My new <a href=\"myHouse.com\">home</a> is <B>very</B> nice!";

String after =
Regex.replace(before, @"<(?:.|\n)+?>", "");

Try that.

Bob said:
Thanks!

I'm going to have to play with them to understand.

bob
(?![^<]*)<[^>]*?>

<(?:.|\n)+?>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Regex woes 8
Regex help needed 1
Need help in Regex. 9
Newbie question about Regex 8
Regex 1
Regex expression to get href value in c# 1
Regex - Matching URLS 2
RegEx Format Help 4

Top