Link to home
Start Free TrialLog in
Avatar of zattz
zattz

asked on

C# Regular Expression Help

Hi

I am having trouble with a regular expression.

The expression is:
<description>.*?</description>

The content I am running the expression on is:
<description>hello</description>

that works fine, but if I put a line break in the middle of my content it does not work. eg:

<description>he
llo</description>

It does not produce any matches on the above content. How can I get my expression to work even with line breaks in the content.

Thanks
SOLUTION
Avatar of ddrudik
ddrudik
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I'm also puzzled by your use of the asterisk followed by the question mark -

the question mark makes input optional (actually, it allows zero or one of the preceeding character set).

The asterisk means "zero, one or more repetitions".
(You may like to see: http://www.regular-expressions.info/repeat.html)

In this case, I think the question mark is unnecessary, and possibly confusing the regex parser. Did you have a reason for it particularly?

Regards,
bgs264

If the regular expression engine support it
*? means match as few as possible
* means match as much as possible
so if you have
<description>xxx </description> <description>yyy</description>
* would match
<description>xxx </description> <description>yyy</description>
and *? would match
<description>xxx </description>
Avatar of zattz
zattz

ASKER

No I didnt. I dont really know what im doing!

Thanks for the help :)
It's impressive that you're using regular expressions if you're new to them, they can be very powerful for string validation.

Have a look around regular-expressions.info for some support, it is a very good site.

Good luck and happy programming

bgs264
Avatar of zattz

ASKER

thanks for the tip