By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,277 Members | 1,433 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,277 IT Pros & Developers. It's quick & easy.

Regex: banana or apple?

P: n/a
Hi,

I'm wondering how to write a regex matching a sentence
like:

"I'm eating a (banana|apple) for my health."

Also, I'd like to know if there's a shorthand for
multiplication of a single character, for instance to
indicate a 7-digit number.

Thanks!
Nov 15 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi Ranier,

"Ranier Dunno" <an*******@discussions.microsoft.com> wrote in message
news:02****************************@phx.gbl...
Hi,

I'm wondering how to write a regex matching a sentence
like:

"I'm eating a (banana|apple) for my health."

Try with this:
(I\'m\seating\sa\s(banana|apple)\sfor\smy\shealth)
Also, I'd like to know if there's a shorthand for
multiplication of a single character, for instance to
indicate a 7-digit number.


Sure there is:
If you want exactly 7digits you would write:
\d{7}

You might also check Regex builder free great utility Expresso.
http://www12.brinkster.com/ultrapico/Expresso.htm

--
Miha Markic - RightHand .NET consulting & software development
miha at rthand com
Nov 15 '05 #2

P: n/a
Hello

To match 7 digit number use [0-9]{7}

also see
http://msdn.microsoft.com/library/en...uantifiers.asp
http://msdn.microsoft.com/library/en...terclasses.asp

Best regards
Sherif

"Ranier Dunno" <an*******@discussions.microsoft.com> wrote in message
news:02****************************@phx.gbl...
Hi,

I'm wondering how to write a regex matching a sentence
like:

"I'm eating a (banana|apple) for my health."

Also, I'd like to know if there's a shorthand for
multiplication of a single character, for instance to
indicate a 7-digit number.

Thanks!

Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.