Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use <code>(?=…)</code> <a href="http://www.regular-expressions.info/lookaround.html" rel="noreferrer"><em>positive lookahead</em></a>; it asserts that a given pattern can be matched. You'd anchor at the beginning of the string, and one by one, in any order, look for a match of each of your patterns.</p> <p>It'll look something like this:</p> <pre><code>^(?=.*one)(?=.*two)(?=.*three).*$ </code></pre> <p>This will match a string that contains <code>"one"</code>, <code>"two"</code>, <code>"three"</code>, in any order (<a href="http://www.rubular.com/r/QFEfj9lMn3" rel="noreferrer">as seen on rubular.com</a>).</p> <p>Depending on the context, you may want to <a href="http://www.regular-expressions.info/anchors.html" rel="noreferrer">anchor</a> on <code>\A</code> and <code>\Z</code>, and use single-line mode so <a href="http://www.regular-expressions.info/dot.html" rel="noreferrer">the dot</a> matches everything.</p> <p>This is not the most efficient solution to the problem. The best solution would be to parse out the words in your input and putting it into an efficient set representation, etc.</p> <h3>Related questions</h3> <ul> <li><a href="https://stackoverflow.com/questions/3092797/how-does-the-regular-expression-work/">How does the regular expression <code>(?&lt;=#)[^#]+(?=#)</code> work?</a></li> </ul> <hr> <h3>More practical example: password validation</h3> <p>Let's say that we want our password to:</p> <ul> <li>Contain between 8 and 15 characters</li> <li>Must contain an uppercase letter</li> <li>Must contain a lowercase letter</li> <li>Must contain a digit</li> <li>Must contain one of special symbols</li> </ul> <p>Then we can write a regex like this:</p> <pre><code>^(?=.{8,15}$)(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[!@#$%^&amp;*]).*$ \__________/\_________/\_________/\_________/\______________/ length upper lower digit symbol </code></pre>
    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