Regex problem with with carriage returns

G

Guest

I have placed html in the database. I am trying to capture items between two
text blocks.
The content string is like the following
</FONT><BR>
<BR>
<BR>
some text here<BR>
<A NAME="

I am trying to capture the 'some text here' with the following regex. I am
using the following reg expression however i believe i am having problems
with the carriage returns.

Dim ResultString As String
Try
ResultString = Regex.Match(SubjectString,
"<BR>(\r\n)<BR>(\r\n)<BR>(.*?)<BR>(\r\n)<A",
RegexOptions.Singleline).Groups(1).Value
Catch ex As ArgumentException
'Syntax error in the regular expression
End Try

When i run this in vb.net app resultstring is always ""

Any one have an idea of what i am doing wrong here?
thx
dave
 
R

RonT

Dave,

I'm not an expert on regular expressions, but I have had to deal with some
recently and have learned enough that I might be able to help.

In your original regular expression you forgot about the carriage return
just prior to your "some text here".

Change: "<BR>(\r\n)<BR>(\r\n)<BR>(.*?)<BR>(\r\n)<A"
To "<BR>(\r\n)<BR>(\r\n)<BR>(\r\n)(.*)<BR>(\r\n)<A"

Note that I also removed the "?". I don't believe it is needed. Also, your
desired text would be the fourth group, not the first, so change
Groups(1).Value to Groups(4).Value.

For an even simpler expression, try changing your regular expression to:

"<BR>\r\n(.+)<BR>" and leave Groups(1).Value as it is.

I hope this helps.

Ron
 

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

Top