Difference between revisions of "Regular Expression"

From GLMWiki
Jump to: navigation, search
(Created page with "RegEx can be tricky! Hopefully this will provide some help. This is an example of perl-regex format which is used in Netbeans and Atom <pre> a-c(\d[{2-2}]\d{1}?[{0-9}]\d) </p...")
 
Line 6: Line 6:
 
</pre>
 
</pre>
  
This will match a-c213 as well as a-c2199
+
This will match a-c213 as well as a-c2199. It will not match b2199 nor a-c229. Can you figure out why?
 +
 
 +
The ? makes the following statement optional.
 +
 
 +
\d is a digit
 +
 
 +
[{x-y}] indicates a range from x to y. This can be alphanumeric.
 +
 
 +
{1} indicates that just that character is accepted.
 +
 
 +
Everything outside the parentheses is literal. So "a-c" matches that string, literally.

Revision as of 15:44, 25 August 2016

RegEx can be tricky! Hopefully this will provide some help.

This is an example of perl-regex format which is used in Netbeans and Atom

a-c(\d[{2-2}]\d{1}?[{0-9}]\d)

This will match a-c213 as well as a-c2199. It will not match b2199 nor a-c229. Can you figure out why?

The ? makes the following statement optional.

\d is a digit

[{x-y}] indicates a range from x to y. This can be alphanumeric.

{1} indicates that just that character is accepted.

Everything outside the parentheses is literal. So "a-c" matches that string, literally.