309

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.

3
  • 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? Commented May 22, 2009 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 =) Commented May 22, 2009 at 19:10
  • 6
    @echoblaze: If you’re processing XML, why don’t you use an XML parser? That would be much easier than using regular expressions. Commented May 22, 2009 at 19:25

1 Answer 1

485

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($|[^_])))).*
Sign up to request clarification or add additional context in comments.

14 Comments

Is this restricted to any particular regex engines?
I only ask because that second one still seems to match tbd_ in my test. The first one is great though.
Take a look at regular-expressions.info’s flavor comparison: regular-expressions.info/refflavors.html
@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.
@balabaster: I don’t think he’s looking for empty strings. But if so, he can easily change that by replacing the .+ by .*
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.