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!
willsherwoodAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Marco GasiFreelancerCommented:
Use this:

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

-saige-
0
willsherwoodAuthor Commented:
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_
0
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Marco GasiFreelancerCommented:
Then this:

(?<!=db_)\ABC
0
Marco GasiFreelancerCommented:
Sorry

(?<!db_)ABC
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
willsherwoodAuthor Commented:
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
0
willsherwoodAuthor Commented:
ooops  nevermind, that last one matches the entire line  :(
0
Marco GasiFreelancerCommented:
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
0
willsherwoodAuthor Commented:
(?<!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
0
willsherwoodAuthor Commented:
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:)
0
willsherwoodAuthor Commented:
(?<!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!
0
it_saigeDeveloperCommented:
https://www.regex101.com/ is an excellent online tester

-saige-
0
Marco GasiFreelancerCommented:
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 :)
0
willsherwoodAuthor Commented:
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!
0
Marco GasiFreelancerCommented:
Great! I was very surprised to hear that didn't work :-)
0
willsherwoodAuthor Commented:
Thanks all!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Regular Expressions

From novice to tech pro — start learning today.