?
Solved

Nearest match RegEx

Posted on 2012-08-27
2
Medium Priority
?
551 Views
Last Modified: 2012-08-27
I have this text
(Objectid < 100 OR ObjectID > 500) AND (apple OR 10a) W/5 Bill

I want to get nearest string with in() having And Or in it nearest W/digit.

I want to get only (apple OR 10a) and not (Objectid < 100 OR ObjectID > 500) AND (apple OR 10a)

I m using
(?<DTVal>\(.*?(and|or|not).*?\))\s*(w|pre)/\d+\s*

Open in new window


But it brings back whole string instead of shortest.
0
Comment
Question by:chambarish
2 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 38337885
Try:

(?<DTVal>(\([^()]+\b(?:AND|OR)\b[^()]+\))\s*W/\d+)

Open in new window

0
 

Author Comment

by:chambarish
ID: 38338445
Yeps it works, however can I get regex in other case as well as in.

(test or best) W/5 AND (apple OR 10a) AND (Objectid < 100 OR ObjectID > 500) in the same reg EX.

In the above example I should get (test or best)  (apple OR 10a)
Thanks for your help.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses
Course of the Month16 days, 17 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question