I'm processing a bunch of tables using this program, but I need to ignore ones that start with the label "tbd_". So far I have something like [^tbd_] but that simply not match those characters.
Asked
Active
Viewed 2.7e+01k times
256
-
How does SchemaSpy work? Are you passing it a list of table names or are you passing it a regex and it's doing the matching? – Mark Biek May 22 '09 at 18:57
-
I'm passing a regex (it's the -i flag) and it'll import the matches, or so it says in any case =) – echoblaze May 22 '09 at 19:10
-
5@echoblaze: If you’re processing XML, why don’t you use an XML parser? That would be much easier than using regular expressions. – Gumbo May 22 '09 at 19:25
1 Answers
415
You could use a negative look-ahead assertion:
^(?!tbd_).+
Or a negative look-behind assertion:
(^.{1,3}$|^.{4}(?<!tbd_).*)
Or just plain old character sets and alternations:
^([^t]|t($|[^b]|b($|[^d]|d($|[^_])))).*
Nuno André
- 3,500
- 1
- 24
- 38
Gumbo
- 620,600
- 104
- 758
- 828
-
9
-
1I only ask because that second one still seems to match tbd_ in my test. The first one is great though. – Mark Biek May 22 '09 at 19:01
-
6Take a look at regular-expressions.info’s flavor comparison: http://www.regular-expressions.info/refflavors.html – Gumbo May 22 '09 at 19:02
-
1@Gumbo - should that not end .* instead of .+? A string that is tbd_ also starts with that... therefore by definition doesn't need to be followed by any other characters? Otherwise, good example. It *does* require a regex engine that supports lookaround though. – BenAlabaster May 22 '09 at 19:04
-
1@balabaster: I don’t think he’s looking for empty strings. But if so, he can easily change that by replacing the `.+` by `.*` – Gumbo May 22 '09 at 19:07
-
Not looking for empty strings, thanks for the help! For some reason it's not working with my regex checker: http://www.bastian-bergerhoff.com/eclipse/features/web/QuickREx/toc.html but I'll finish the xml script and see how that goes – echoblaze May 22 '09 at 19:16
-
-
I am having issues with the first example using egrep, python's re, as well as a few online regex parsers (i.e. [Gskinner](http://gskinner.com/RegExr/)). It looks like these don't like a look-ahead with nothing preceeding. Anyone else seeing this issue? – michaelxor Oct 22 '12 at 19:12
-
Actually, after playing around a little more it looks like egrep is the only one that really doesn't like example #1. I am able to make this work with python's re or Gskinner as long as the look-ahead is not the ONLY matchable string thing in the pattern (i.e. this does not work: '^(!?somestring)', but this does: '^(?!somestring).+'). – michaelxor Oct 22 '12 at 20:26
-
This works in Visual Studio 2015 Find in Files. This expression uses both a negative look-ahead and a negative look-behind to find all C++ identifiers that start with "do_", but do not start with "do_Mode" and do not end with "Desc" or "Msg": "do_(?!Mode)(_\w+|[\w-[0-9_]]\w*(? – Scott Hutchinson May 11 '17 at 22:17
-
1"Use a negative look-ahead assertion", I am sure I've been on the receiving end of a few of those. – Davos Aug 14 '19 at 01:19