Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The short answer is along the lines of:</p> <pre><code>grep "abc[^(?:def)]*ghi" ./testregex </code></pre> <p>That's based on a testregex file like so:</p> <pre><code>abcghiabc abcdefghi abcghi </code></pre> <p>The output will be:</p> <pre><code>$ grep "abc[^(?:def)]*ghi" ./testregex abcghiabc abcghi </code></pre> <p>Mapped to your use-case, I'd wager this translates roughly to:</p> <pre><code>grep -lri "stringA[^(?:stringB)]*stringC" ./*.sql </code></pre> <p>Note that I've removed the ".*" between each string, since that will match the very string that you're attempting to exclude.</p> <p>Update: The original question now calls out line breaks, so use grep's -z flag:</p> <pre><code>-z </code></pre> <blockquote> <p>suppress newline at the end of line, subtituting it for null character. That is, grep knows where end of line is, but sees the input as one big line.</p> </blockquote> <p>Thus:</p> <pre><code>grep -lriz "stringA[^(?:stringB)]*stringC" ./*.sql </code></pre> <p>When I first had to use this approach myself, I wrote up the following explanation...</p> <blockquote> <p>Specifically: I wanted to match "any character, any number of times, non-greedy (so defer to subsequent explicit patterns), and NOT MATCHING THE SEQUENCE />".</p> <p>The last part is what I'm writing to share: "not matching the sequence />". This is the first time I've used character sequences combined with "any character" logic.</p> <p>My target string:</p> <p><code>&lt;img class="photo" src="http://d3gqasl9vmjfd8.cloudfront.net/49c7a10a-4a45-4530-9564-d058f70b9e5e.png" alt="Iron or Gold" /&gt;</code></p> <p>My first attempt:</p> <p><code>&lt;img.*?class="photo".*?src=".*?".*?/&gt;</code></p> <p>This worked in online regex testers, but failed for some reason within my actual Java code. Through trial and error, I found that replacing every ".<em>?" with "[^&lt;>]</em>?" was successful. That is, instead of "non-greedy matching of any character", I could use "non-greedy matching of any character except &lt; or >".</p> <p>But, I didn't want to use this, since I've seen alt text which includes these characters. In my particular case, I wanted to use the character sequence "/>" as the exclusion sequence -- once that sequence was encountered, stop the "any character" matching.</p> <p>This brings me to my lesson:</p> <p>Part 1: Character sequences can be achieved using (?:regex). That is, use the () parenthesis as normal for a character sequence, but prepend with "?:" in order to prevent the sequence from being matched as a target group. Ergo, "(?:/>)" would match "/>", while "(?:/>)*" would match "/>/>/>/>".</p> <p>Part 2: Such character sequences can be used in the same manner as single characters. That is, "[^(?:/>)]*?" will match any character EXCEPT the sequence "/>", any number of times, non-greedy.</p> <p>That's pretty much it. The keywords for searching are "non-capturing groups" and "negative lookahead|lookbehind", and the latter feature goes much deeper than I've gone so far, with additional flags that I don't yet grok. But the initial understanding gave me the tool I needed for my immediate task, and it's a feature that I've wondered about for awhile -- thus, I figured I'd share the basic introduction in case any of you were curious about tucking it away in your toolset.</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload