Link to home
Start Free TrialLog in
Avatar of willsherwood
willsherwood

asked on

REGEX simple ! question

I want to match all occurrences of ABC that are not preceded by  db_

xyzABC    will match
xyzdb_ABC   won't match

i tried
*(!db_)ABC  
but it still matches.

please help find my mistake

thanks!
Avatar of Marco Gasi
Marco Gasi
Flag of Spain image

Use this:

(?<!=db_)\w+
/(db_ABC)+|ABC+/g will provide all matches of db_ABC in group 1 and all matches of ABC in group 0.

-saige-
Avatar of willsherwood
willsherwood

ASKER

sorry for the confusion.
ABC is exact literal text (not meta placeholder text for my example)
i don't want to match ABC   when  the ABC identifier is directly preceded by  db_
Then this:

(?<!=db_)\ABC
ASKER CERTIFIED SOLUTION
Avatar of Marco Gasi
Marco Gasi
Flag of Spain 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
hmmmm  sorry, plain ABC doesn't match now.
i experimented some more and tried
*!(db_)ABC

and that seems to work (i hope) - does that look reasonable?
(i had the not operator in the wrong place
ooops  nevermind, that last one matches the entire line  :(
Try this
(?<!db_)ABC(?x:)

The last expression means 'Ignore Pattern/Whitespace'.
With this I get 3 matches using following text:

xyzABC    will match
xyzdb_ABC   won't match
ABC
DSDSABC
(?<!db_)ABC    unfortunately does not match anything  (even just ABC)

to recap:
i'd like the following examples to match:
(nothing)ABCetc1
123ABCetc2
_ABCetc3

but the following
not to match:
(nothing)db_ABCetc1
anythingdb_ABCetc2

thanks
I suspect my simplification is causing the issue for the test example, my apologies.

here's the real life example being searched for:
(?<!db_)SingleFieldQuery(x:)
(?<!db_)SingleFieldQuery(?x:)    matches nothing, sorry.

plain SingleFieldQuery matches, for example:

$CustAcctID = SingleFieldQuery("SELECT

and

// db_SingleFieldQuery       (don't want this matched)

is there an online Regex tester (i found several that are installable programs, but none that
one can enter a searchstring and a sample text to search/replace)

(i'm wondering if it's a bug in the particular implementation of regex in the tool i'm using? )

thanks!
SOLUTION
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
In the suggested tester the regex works without the parameter to Ignore PatternWhiteSpace required by my tester. So it seems work the regex suggested in my post ID: 40692307. I'm a bit confused about the reason one tester require some additiona parameter and other don't... Anyway, good link, @saige :)
aha!  excellent,
it's evidently a bug in the regex engine for the tool i'm using!

THANK YOU

(?<!db_)SingleFieldQuery    works to differentiate the two test cases!
Great! I was very surprised to hear that didn't work :-)
Thanks all!