Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It looks like you can use <code>MAN(?!.*PN)</code>. This matches <code>MAN</code> and uses negative lookahead to make sure that it's not followed by <code>PN</code> (<a href="http://www.rubular.com/r/BP0T80KVsR" rel="nofollow noreferrer">as seen on rubular.com</a>).</p> <p>Given <code>MAN_PN_MAN_BLEH</code>, the above pattern will find the second <code>MAN</code>, since it's not followed by <code>PN</code>. If you want to validate the entire string and make sure that there's no <code>MAN.*PN</code>, then you can use something like <code>^(?!.*MAN.*PN).*MAN.*$</code> (<a href="http://www.rubular.com/r/QtlvGlfisu" rel="nofollow noreferrer">as seen on rubular.com</a>).</p> <h3>References</h3> <ul> <li><a href="http://www.regular-expressions.info/lookaround.html" rel="nofollow noreferrer">regular-expressios.info/Lookarounds</a></li> </ul> <h3>Related questions</h3> <ul> <li><a href="https://stackoverflow.com/questions/3077566/how-can-i-check-if-every-substring-of-four-zeros-is-followed-by-at-least-four-one/3080023#3080023">How can I check if every substring of four zeros is followed by at least four ones using regular expressions?</a></li> </ul> <hr> <h3>Non-regex option</h3> <p>If the strings are to be matched literally, then you can also check for indices of substring occurrences.</p> <p>In Python, <code>find</code> and <code>rfind</code> return lowest and highest index of substring occurrences respectively.</p> <p>So to make sure that <code>string1</code> occurs but never followed by <code>string2</code>, and both returns <code>-1</code> if the string is not found, so it looks like you can just test for this condition:</p> <pre><code>string.rfind(s, string2) &lt; string.find(s, string1) </code></pre> <p>This compares the leftmost occurrence of <code>string1</code> and the rightmost occurrence of <code>string2</code>.</p> <ul> <li>If neither occurs, both are <code>-1</code>, and result is <code>false</code></li> <li>If <code>string1</code> occurs, but <code>string2</code> doesn't, then result is <code>true</code> as expected</li> <li>If both occurs, then the rightmost <code>string2</code> must be to the left of the leftmost <code>string1</code> <ul> <li>That is, no <code>string1</code> is ever followed by <code>string2</code></li> </ul></li> </ul> <h3>API links</h3> <ul> <li><a href="http://docs.python.org/library/string.html#string.find" rel="nofollow noreferrer"><code>find</code></a></li> <li><a href="http://docs.python.org/library/string.html#string.rfind" rel="nofollow noreferrer"><code>rfind</code></a></li> </ul>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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