473,466 Members | 1,408 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Regex: banana or apple?

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
2 1431
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Sebastian Araya | last post by:
Hello, I have a string like this: var1: value1...valueI var2: value1...valueJ ... varN: value1...valueK this is an example: breakfast: coffee eggs lunch: sandwich apple dinner: chicken...
3
by: Flos | last post by:
Hello! I want to make a validation for a string which can be only letters AND space. for example "apple house", but not "apple3 house" i have found if (preg_match ("//", $string)) return...
6
by: darrel | last post by:
I'm using a regex and want to find a specific tag, like TABLE this: (<)(table) matches this: <table <turkey
8
by: Jeff | last post by:
I have a list like this: Reckless Engineer St Bonaventures The Blue Mountain The Croft The Cube Club The Folk house I'd like to reorder that ignoring the leading "The".
15
by: morleyc | last post by:
Hi, i would like to remove a number of characters from my string (\t \r \n which are throughout the string), i know regex can do this but i have no idea how. Any pointers much appreciated. Chris
9
by: Ronald S. Cook | last post by:
Can I write If MyString = "Apple" Or MyString = "Orange" Or MyString = "Pear" Then to something more compact like If MyString In ("Apple", "Orange", "Pear") Then My last line obviously...
6
by: Charles | last post by:
Hello, I'm trying to extract the home page URL out of a any URL from the same web site For instance if I'm on http://www.regular-expressions.info/javascriptexample.html I want to extract...
29
Niheel
by: Niheel | last post by:
The Apple invasion into corporate has started and I can't say if I am excited or scared. As an IT manager, I have nightmares over all the support and technical issues of integrating Apple hardware...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.