Link to home
Start Free TrialLog in
Avatar of tmajor99
tmajor99

asked on

Regular Expression to detect "/" within "( )".

I need a regular expression that can search for a "/" within "( )".  

Data

Wall-Mount (InWall / Plate)    = True
Wall/Mount (test)                     = Not True
Wall-Mount  (test)                    = Not True
(1/2) Test                                   = True
(Test, Test/TEST) 123               = True
/Test                                           = Not True
/Test/                                         = Not True
(/Test Abc                                  = Not True - No closing ")"
Avatar of Russ Suter
Russ Suter

This should do it:
(?<=[/(][^//]*)([//])(?=[^//]*[/)])

Open in new window

The middle group will only match if the prefix and suffix are both present.
ASKER CERTIFIED SOLUTION
Avatar of wilcoxon
wilcoxon
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I am not an expert of regular expression but why can we not use simply this?

\(.*\/.*\)

Open in new window

Subodh, the primary reason is because it would match things like (...) / (...) where there are parens on both sides but the slash is not within them.
Yes, that makes sense.

I proposed that pattern based on the sample data only. :)