|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
[Regular Expression] (aaa AND bbb) OR (ccc AND ddd)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) Click the link below for all your RegEx needs :)
http://www.google.com/search?client=firefox-a&rls=org.mozilla%3Aen-US%3Aofficial_s&hl=en&q=regular+expression+test&btnG=Google+Search On Fri, 3 Nov 2006 14:13:48 -0000, "Robinson"
<toomuchspamhaspassed@myinboxtoomuchtoooften.com> wrote: >Click the link below for all your RegEx needs :) I've found nothing about matching> >http://www.google.com/search?client=firefox-a&rls=org.mozilla%3Aen-US%3Aofficial_s&hl=en&q=regular+expression+test&btnG=Google+Search two words at the same time or two other words at the same time 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/UserSamples/Details.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/default.asp?url=/library/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. -- Show quoteHide quoteHope this helps Jay B. Harlow ..NET Application Architect, Enthusiast, & Evangelist T.S. Bradley - http://www.tsbradley.net "teo" <t**@inwind.it> wrote in message news:1ahmk2h9hpfvd1nvfhn8c89ocm5j2kgjib@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) > >teo, that's right>> 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? 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.0and 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? ) Teo,
>>Does dog have to precede cat or can it follow cat? setting the precedence generally means you doubled the number of expressions > 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...) as now you need: MyString = "(dog AND cat) OR (cat AND dog)" >>What about interleaving characters? It means characters between the words.> what do you mean with 'interleaving' characters? > I never met this word (I'm Italian) 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) -- Show quoteHide quoteHope this helps Jay B. Harlow ..NET Application Architect, Enthusiast, & Evangelist T.S. Bradley - http://www.tsbradley.net "teo" <t**@inwind.it> wrote in message news:9tdqk29gv4nmo76s90u31nh7vcorjq3302@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? ) |
|||||||||||||||||||||||