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
Regular ExpressionsC#

Avatar of undefined
Last Comment
zattz

8/22/2022 - Mon
SOLUTION
ddrudik

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER CERTIFIED SOLUTION
bgs264

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
bgs264

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

ozo

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>
ASKER
zattz

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

Thanks for the help :)
Your help has saved me hundreds of hours of internet surfing.
fblack61
bgs264

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
ASKER
zattz

thanks for the tip