473,385 Members | 1,472 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

[Regular Expression] (aaa AND bbb) OR (ccc AND ddd)

teo

I need to implement a boolean evaluation
in a Regular Expression like this:
(aaa AND bbb) OR (ccc AND ddd)
(see the #3 case)
- - -

1)
If I need to match a single word only,
no problem:

MyString = "hallo"
MioMatch = Regex.Match(MyBigText, MyString)

2)
If I need to match a couple of words in OR relation,
I think I have to use the 'pipe' |
in this way:

MyString = "dog|cat"
MioMatch = Regex.Match(MyBigText, MyString)

3) here the problem

If I need to match
a couple of words (in AND relation),
and evaluate them in OR relation
with another couple of words (in AND relation),
like this:

(dog AND cat) OR (milk AND coffe)

How can I achieve this ?

This obviously doesn't work:
MyString = "(dog AND cat) OR (milk AND coffe)"
MioMatch = Regex.Match(MyBigText, MyString)

Nov 3 '06 #1
5 2963
Click the link below for all your RegEx needs :)

http://www.google.com/search?client=...=Google+Search
Nov 3 '06 #2
teo
On Fri, 3 Nov 2006 14:13:48 -0000, "Robinson"
<to******************@myinboxtoomuchtoooften.comwr ote:
>Click the link below for all your RegEx needs :)

http://www.google.com/search?client=...=Google+Search
I've found nothing about matching
two words at the same time
or
two other words at the same time

Nov 3 '06 #3
teo,
MyString = "(dog AND cat) OR (milk AND coffe)"
Are you saying you want to find both dog & cat in a string or both milk &
coffe in a string?

Does dog have to precede cat or can it follow cat?
What about interleaving characters?
Some RegEx resources:

Expresso:
http://www.ultrapico.com/Expresso.htm

RegEx Workbench:
http://www.gotdotnet.com/Community/U...aspx?SampleGui...

A tutorial & reference on using regular expressions:
http://www.regular-expressions.info/

The MSDN's documentation on regular expressions:
http://msdn.microsoft.com/library/de...ary/en-us/cpge...

Expresso & RegEx Workbench are helpful tools for learning regular
expressions & testing them.

I use the regular-expressions.info as a general regex reference, then fall
back to MSDN for the specifics. The above link is .NET 1.x; I don't have the
..NET 2.0 link handy; not sure if any thing changes in 2.0.
--
Hope this helps
Jay B. Harlow
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"teo" <te*@inwind.itwrote in message
news:1a********************************@4ax.com...
>
I need to implement a boolean evaluation
in a Regular Expression like this:
(aaa AND bbb) OR (ccc AND ddd)
(see the #3 case)
- - -

1)
If I need to match a single word only,
no problem:

MyString = "hallo"
MioMatch = Regex.Match(MyBigText, MyString)

2)
If I need to match a couple of words in OR relation,
I think I have to use the 'pipe' |
in this way:

MyString = "dog|cat"
MioMatch = Regex.Match(MyBigText, MyString)

3) here the problem

If I need to match
a couple of words (in AND relation),
and evaluate them in OR relation
with another couple of words (in AND relation),
like this:

(dog AND cat) OR (milk AND coffe)

How can I achieve this ?

This obviously doesn't work:
MyString = "(dog AND cat) OR (milk AND coffe)"
MioMatch = Regex.Match(MyBigText, MyString)
Nov 4 '06 #4
teo
>teo,
>MyString = "(dog AND cat) OR (milk AND coffe)"
Are you saying you want to find both dog & cat in a string or both milk &
coffe in a string?
that's right

>Does dog have to precede cat or can it follow cat?
this is not important now, both the cases are good

(anyway if there is a way or parameter
to set the precedence it will be surely useful in the future...)
>What about interleaving characters?
what do you mean with 'interleaving' characters?

I never met this word (I'm Italian)

>Some RegEx resources:
Thanks, I previously went deep on MSDN fx 2.0
and on the renowed VBNet book by F.Balena,
and on the shareware version of 'RegEx Buddy '
(Now REgExBuddy is expired so I'll go with Expresso )

but found tons of samples about one or more chars,
but NO sample about one or more words and their AND or OR
boolean evaluation

(I met only the OR operand like dog|cat ,
but it is not my case)
The implementation of that simple boolean evaluation
like (dog AND cat) OR (milk AND coffe)
still remains...
(maybe the interleaving chars could help,
but what are those? )
Nov 5 '06 #5
Teo,
>>Does dog have to precede cat or can it follow cat?
this is not important now, both the cases are good
(anyway if there is a way or parameter
to set the precedence it will be surely useful in the future...)
setting the precedence generally means you doubled the number of expressions
as now you need:

MyString = "(dog AND cat) OR (cat AND dog)"

>>What about interleaving characters?
what do you mean with 'interleaving' characters?
I never met this word (I'm Italian)
It means characters between the words.

In other words would "I had milk in my coffe" or "it rained cats and dogs"
match?

AND is simply listing the characters:

dogcat

However that says there are no interleaving characters (no characters)
between the words.

To introduce interleaving characters you need:

dog.*cat

or

dog.+cat

The first says dog followed by any character zero or more times followed by
cat. While the second says dog followed by any character one or more times.

Instead of . I would consider \s which says white space.

OR is simply alternation:

dog|milk

Will match a string with dog it in or milk in it.
You should be able to use a string such as (untested):

MyString = (dog.*cat)|(cat.*dog)|(milk.*coffe)|(coffe.*milk)

--
Hope this helps
Jay B. Harlow
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"teo" <te*@inwind.itwrote in message
news:9t********************************@4ax.com...
teo,
>>MyString = "(dog AND cat) OR (milk AND coffe)"
Are you saying you want to find both dog & cat in a string or both milk &
coffe in a string?

that's right

>>Does dog have to precede cat or can it follow cat?

this is not important now, both the cases are good

(anyway if there is a way or parameter
to set the precedence it will be surely useful in the future...)
>>What about interleaving characters?

what do you mean with 'interleaving' characters?

I never met this word (I'm Italian)

>>Some RegEx resources:

Thanks, I previously went deep on MSDN fx 2.0
and on the renowed VBNet book by F.Balena,
and on the shareware version of 'RegEx Buddy '
(Now REgExBuddy is expired so I'll go with Expresso )

but found tons of samples about one or more chars,
but NO sample about one or more words and their AND or OR
boolean evaluation

(I met only the OR operand like dog|cat ,
but it is not my case)
The implementation of that simple boolean evaluation
like (dog AND cat) OR (milk AND coffe)
still remains...
(maybe the interleaving chars could help,
but what are those? )
Nov 5 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: pekka niiranen | last post by:
Hi there, I have perl script that uses dynamically constructed regular in this way: ------perl code starts ---- $result ""; $key = AAA\?01; $key = quotemeta $key; $line = " ...
2
by: Jeff | last post by:
I'd like to write an XPath expression that gets a node with 2 particular children. I thought this would work: /AAA/BBB/CCC/following-silbing::DDD/parent::node() on xml like this: AAA BBB
1
by: John Smith | last post by:
how to do in order to retrieve the content between '<AAA>' and </AAA> let's say the text is : <AAA>a</<AAA><BBB><AAA>ab</AAA></BBB> ... ???
2
by: Morten Snedker | last post by:
In another thread I found this snippet for validating an e-mail: ^(+)@((\{1,3}\.{1,3}\.{1,3}\.)|((+\.)+))({2,4}|{1,3})(\]?)$ Would someone please help to read this? I don't get the slashes,...
8
by: yaron | last post by:
Hi all, let say that my string is : /// <author> aaa /// <author> bbb /// <author> ccc 1. how do i match all the authors except author aaa ? 2. how do i append the string "2006" to the...
4
by: Gert Conradie | last post by:
I need to list all the key/value pairs of and HTML tag. I already have the complete tag as an text string. For example: (Worst case scenario where standards was not followed in the past) <myTag...
2
by: Sharun | last post by:
Python newbie here. I am not clear about how the matching is taking place when I do the following 'aaa bbb\r\n ccc ddd\r\n eee fff' 'fff' I am trying to find the substring starting with...
47
by: Henning_Thornblad | last post by:
What can be the cause of the large difference between re.search and grep? This script takes about 5 min to run on my computer: #!/usr/bin/env python import re row="" for a in range(156000):...
9
by: netimen | last post by:
I have a text containing brackets (or what is the correct term for '>'?). I'd like to match text in the uppermost level of brackets. So, I have sth like: 'aaaa 123 < 1 aaa < t bbb < a <tt ff 2...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.