Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / June 2007

Tip: Looking for answers? Try searching our database.

Regular Epx

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
guate911 - 29 May 2007 21:03 GMT
I am using the Regular Expression Validator, and I need to test for a
pattern that allows words in quotes, or multiple words in quotes
seperated by the word "OR".

I can get the single word in quotes check [^"]*, but I don't know how
to add the OR delimeter. Any suggestions?

See example Below.

1) "TEST"
2"TEST1" OR "Test2" OR "Test3"

Thanks
Papanii - 30 May 2007 00:50 GMT
I think it is much more complicated than that. If i understand your question
correctly the expression i have below should work. I have tested it on a few
strings and it seems to work.

expression = ^['""]\w+['""]\s+(OR\s+['""]\w+['""])+|^['""]\w+['""]\s*$

note: expression implemented using c# regular expression metacharacters..

--Papanii

>I am using the Regular Expression Validator, and I need to test for a
> pattern that allows words in quotes, or multiple words in quotes
[quoted text clipped - 9 lines]
>
> Thanks
Kevin Spencer - 30 May 2007 11:55 GMT
(?i)(?:\s*OR\s*)?"(?<word>\w+)"

This captures any sequence of word characters (digits or letters) enclosed
in quotes which are preceded by 0 or more sequences of 0 or more spaces
followed by the word "OR" followed by 0 or more spaces, and names the group
with the word in it "word." The initial sequence is a modifier indicating
that the regular expression is case-insensitive.

Signature

HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

>I am using the Regular Expression Validator, and I need to test for a
> pattern that allows words in quotes, or multiple words in quotes
[quoted text clipped - 9 lines]
>
> Thanks
guate911 - 30 May 2007 22:00 GMT
> (?i)(?:\s*OR\s*)?"(?<word>\w+)"
>
[quoted text clipped - 29 lines]
>
> - Show quoted text -

Thank You So Much! Worked Fine

I have a question though. I am new to regular expressions, and I am
confused as to what the "(?i" Stands for?

Also,

It would not compile while I kept the grouping <word> in the
expression. I removed it, and it worked. How could I modify it, so it
would also pass if I wanted to pass test data like below:

Test Data : "test1" OR "My Test Data2"
It is failing when I include a space in between the quoted words.

Below is my code so far.

Regex regex = new Regex(@" (?i?\s)(?:\s*OR\s*)?""");
passed = regex.IsMatch(TestData);
Kevin Spencer - 31 May 2007 12:32 GMT
> I have a question though. I am new to regular expressions, and I am
> confused as to what the "(?i" Stands for?

>> <snip>The initial sequence is a modifier indicating
>> that the regular expression is case-insensitive.

I prefer not to use Regex Options in my programming code. As I re-use
Regular Expressions, I don't want to have to remember what options to turn
on. Since the Regular Expressions syntax contains modifiers that supply
these options, I use them in the expressions.

> It would not compile while I kept the grouping <word> in the
> expression. I removed it, and it worked. How could I modify it, so it

(?i)(?:\s*OR\s*)?"([^"]*)"

On closer examination, I determined that my original was not robust enough.
The above should work well for you. Here's the explanation:

(?:\s*OR\s*)?

The word "OR" may precede the rest of the match, but is optional (may appear
0 or 1 times), and may have 0 or more spaces before and after it. It is in a
non-capturing group with the quantifier '?' indicating 0 or 1 times.

"([^"]*)

This is a capturing group (I removed the label, which would make it a named
capturing group). It indicates a quote character followed by 0 or more
non-quote characters, followed by a quote character. This way, there may be
any characters between the quotes.

Signature

HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

>> (?i)(?:\s*OR\s*)?"(?<word>\w+)"
>>
>> This captures any sequence of word characters (digits or letters)
>> enclosed
<snip>
> I have a question though. I am new to regular expressions, and I am
> confused as to what the "(?i" Stands for?
[quoted text clipped - 12 lines]
> Regex regex = new Regex(@" (?i?\s)(?:\s*OR\s*)?""");
> passed = regex.IsMatch(TestData);
guate911 - 06 Jun 2007 17:00 GMT
> > I have a question though. I am new to regular expressions, and I am
> > confused as to what the "(?i" Stands for?
[quoted text clipped - 60 lines]
>
> - Show quoted text -

Thanks for the help

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.