zattz
asked on
C# Regular Expression Help
Hi
I am having trouble with a regular expression.
The expression is:
<description>.*?</descript ion>
The content I am running the expression on is:
<description>hello</descri ption>
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
I am having trouble with a regular expression.
The expression is:
<description>.*?</descript
The content I am running the expression on is:
<description>hello</descri
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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</descript ion>
* would match
<description>xxx </description> <description>yyy</descript ion>
and *? would match
<description>xxx </description>
*? means match as few as possible
* means match as much as possible
so if you have
<description>xxx </description> <description>yyy</descript
* would match
<description>xxx </description> <description>yyy</descript
and *? would match
<description>xxx </description>
ASKER
No I didnt. I dont really know what im doing!
Thanks for the help :)
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
Have a look around regular-expressions.info for some support, it is a very good site.
Good luck and happy programming
bgs264
ASKER
thanks for the tip
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