Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>What regular expressions are used for:</strong></p> <p>Regular expressions is a language in itself that allows you to perform complex validation of string inputs. I.e. you pass it a string and it will return true or false if it is a match or not. </p> <p><strong>How regular expressions are used:</strong></p> <ul> <li>Form validation, determine if what the user entered is of the format you want</li> <li>Finding the position of a certain pattern in a block of text</li> <li>Search and replace where the search term is a regex and what to replace is a normal string. </li> </ul> <p><strong>Some regular expression language features:</strong></p> <ul> <li><p><strong>Alternation:</strong> allows you to select one thing or another. Example match only yes or no.</p> <p>yes|no</p></li> <li><p><strong>Grouping:</strong> You can define scope and have precedence using parentheses. For example match 3 color shades.</p> <p>gr(a|e)y|black|white</p></li> <li><p><strong>Quantification:</strong> You can quantify how much of something you want. ? means 1 or 0, * means 0 or more. + means at least one. Example: Accept a binary string that is not empty: </p> <p>(0|1)+</p></li> </ul> <p><strong>Why regular expressions?</strong> </p> <p>Regular expressions make it easy to match strings, it can often replace several dozen lines of source code with a simple small regular expression string. </p> <p><strong>Not for all types of matching:</strong> </p> <p>To understand how something is useful, you should also understand how it is not useful. Regular expressions are bad for certain tasks for example when you need to guarantee that a string has an equal number of parentheses. </p> <p><strong>Available in just about all languages:</strong> </p> <p>Regular expressions are available in just about any programming language. </p> <p><strong>Formal language:</strong></p> <p>Any regular expression can be converted to a deterministic finite state machine. And in this same way you can figure out how to make source code that will validate your regular expression. </p> <p><strong>Example:</strong> </p> <pre><code>[hc]+at </code></pre> <p>matches "hat", "cat", "hhat", "chat", "hcat", "ccchat", and so on, but not "at"</p> <p><a href="http://en.wikipedia.org/wiki/Regular_expression" rel="nofollow noreferrer">Source, further reading</a></p>
 

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