Busy. Please wait.
or

show password
Forgot Password?

Don't have an account?  Sign up 
or

Username is available taken
show password

why


Make sure to remember your password. If you forget it there is no way for StudyStack to send you a reset link. You would need to create a new account.
We do not share your email address with others. It is only used to allow you to reset your password. For details read our Privacy Policy and Terms of Service.


Already a StudyStack user? Log In

Reset Password
Enter the associated with your account, and we'll email you a link to reset your password.

Remove ads
Don't know
Know
remaining cards
Save
0:01
To flip the current card, click it or press the Spacebar key.  To move the current card to one of the three colored boxes, click on the box.  You may also press the UP ARROW key to move the card to the "Know" box, the DOWN ARROW key to move the card to the "Don't know" box, or the RIGHT ARROW key to move the card to the Remaining box.  You may also click on the card displayed in any of the three boxes to bring that card back to the center.

Pass complete!

"Know" box contains:
Time elapsed:
Retries:
restart all cards




share
Embed Code - If you would like this activity on your web page, copy the script below and paste it into your web page.

  Normal Size     Small Size show me how

regex

Regular Expressions

QuestionAnswer
How do you identify a 'mode' for the query? Added to end of expression after '/'
Can modes be combined? Yes
Name all the modes? Standard, Global, Case-insensitive, Multi-line, dot-matches-all
What is the flag for 'standard' mode? No flag as it is the default
What is the flag for 'global' mode? g
What is the flag for 'case-insensitive' mode? i
What is the flag for 'multi-line' mode? m
What is the flag for 'dot-matches-all' mode? s
What is 'standard' mode? Finds the first left-most match.
What is 'global' mode? Finds all matches in target text.
What is 'case-insensitive' mode? Matches without regard to upper/lower case.
What is 'multi-line' mode? Matches across line-breaks.
What is 'dot-matches-all' mode? Matches any single character including the new-line character.
What are the metacharacters? \ . * + - {} [] ^ $ | ? () : ! =
What is a metacharacter? Has special meaning, such as math operators. May be different between regex engines. Can have more than one meaning depending on how it is used.
What is the wildcard character? . (dot)
How do you include characters in search that are also metacharacters? Escape with '\' before them.
How do you identify a group of characters where only one may match that position? Put characters in square brackets '[]'. Only one may match search.
Will: /gr[ea]t/ match: 'great'? No, only 'e' or 'a' may match and both are required for 'great'.
What words will /gr[ea]y/ match? grey or gray
How do you identify a range of characters? A character set with a starting and ending character separated by a dash. [a-k] [a-dp-z]
What will [50-99] match? 5, followed by 0 to 9, followed by 9. i.e. '579', NOT all the numbers from 50 to 99.
How do you identify a character set that is not to be matched? Use the '^' at the start such as [^abc]
How do you include metacharacters in a character set? By default, they do not need escaping except for the characters ']', '-', '^' or '\' which do need escaping.
What are the shorthands for a character set of digits and for a set that are 'not' digits? \d for digit set and \D for non-digit set.
What are the shorthands for a character set, and for one that is 'not' character? \w for character set and \W for non-character set.
What are the shorthands for a whitespace, and for 'not' a whitespace? \s for whitespace and \S for non-whitespace
What is the special consideration for the \w shorthand? Hyphen is not a character but underscore is.
What is a posix bracket expression? A named character set.
How is a posix bracket expression used? It must be contained within a character set expression such as [[:alpha:]] and not on its own otherwise it will be confused for a group of characters to match against instead of a named set.
What is the posix for alphabetic characters? [:alpha:] Same as [a-zA-Z]
What is the posix for numeric characters? [:digit:] Same as [0-9]
What is the posix for alphanumeric characters? [:alnum:] Same as [a-zA-Z0-9]
What is the posix for uppercase alphabetic characters? [:upper:] Same as [A-Z]
What is the posix for lowercase alphabetic characters? [:lower:] Same as [a-z]
What is the posix for punctuation characters? [:punct:]
What is the posix for spaces? [:space:] Same as [\s]
What is the posix for blank characters? (space, tab) [:blank:]
What is the posix for printable characters, spaces? [:print:]
What is the posix for printable characters, no spaces? [:graph:]
What is the posix for control characters? [:cntrl:]
What is the posix for hexidecimal characters? [:xdigit:] Same as [a-f0-9A-F]
Is posix supported by javascript? No, just Ruby, Unix, Perl and PHP
What are the repetition metacharacters? ? * +
What does the repetition metacharacter '+' signify? Preceding item 1 or more times
What does the repetition metacharacter '*' signify? Preceding item 0 or more times
What does the repetition metacharacter '?' signify? Preceding item 0 or 1 time
What makes the repetition metacharacter '+' different from the '*' and '?' characters? It requires a match whereas the others do not have to match.
Which does /apples?/ match: apple, apples, applessss Matches apple and apples
Which does /\d\d\d\d*/ match: 123, 1234, 12345 Matches all.
What are the repetition metacharacters? * - preceding item 0 or more times + - preceding item 1 or more times ? - preceding item 0 or 1 time
What does the metacharacter * do? Matches the preceding item 0 or more times
What does the metacharacter + do? Matches the preceding item 1 or more times
What does the metacharacter ? do? Matches the preceding item 0 or 1 time only.
What does this search look for? /\d\d\d\d*/ 3 or more digits, the last(4th) is optional.
What does this search look for? \/d/d/d+/ 3 or more ditits
What syntax is used to identify a quantified repetition? {min, max} {min} {min,}
What does the quantified repetition {4,8} indicate for the preceding item? The preceding item must have at least 4 repetitions up to a maximum of 8.
What does the quantified repetition {2} indicate for the preceding item? The preceding item must have 2 repetitions exactly.
What does the quantified repetition {3,} indicate for the preceding item? The preceding item must have at least 3 repetitions to infinity.
What is a 'greedy' expression? Matches as much as possible before giving control to the next expression part. In the test /.+\.jpg/, the '.+' would give back the '.jpg' found in the match so that it could be matched by the next part.
What is a lazy expression? It uses the metacharacter '?' to make the preceding quantifier a lazy match: +? *? ?? {min,max}? The minimal match is used whenever possible.
How do you group, and what are the advantages of grouping? Use () to group expressions. 1) Can apply repetition operators to a group. 2) Makes expressions easier to read. 3) Captures group for use in matching and replacing.
How can you use grouping to match 'abc' in 'abcabcabcabc'? /(abc)+/
Is /run(s)?/ the same as /runs+/ Yes but sometimes the () can make it easier to see what you're trying to do.
What is the alternation character? The pipe | character.
What is the logic used in the alternation character? Same as an OR expression where the left-most side has higher precedence. It can also be used to provide many options a|b|c|d| etc.
Use the alternation metacharacter to match either applesauce or applejuice. /apple(juice|sauce)/
What will /xyz|abc/ match given 'abcdefxyz'? It will match 'abc' as it is the first match found at the start of the string.
When repeating alternations such as with: /(AA|BB|CC){2}/, does the repeat require the first alternation match found to be the repeated match? No, if 'AA' were found, the next match could still be ANY of the alternations in the group that match.
Can alternations be nested? Yes, but you have to be careful as it can be hard to read as the expression gets more complicated.
What are the anchor metacharacters? ^, $, \A, \Z
What does the anchor metacharacter ^ do? It anchors at the start of a string/line.
What does the anchor metacharacter $ do? It anchors at the end of a string/line.
What does the anchor metacharacter \A do? It anchors at the start of a string, never at the end of a line. (not available in javascript)
What does the anchor metacharacter \Z do? It anchors at the end of a string, never at the start of a line. (not available in javascript)
Describe the following expression: /^apple/ 'apple' must exist at the start of the line only.
Describe the following expression: /^apple$/ 'apple' must exist at both the start and end of the string.
Describe the following expression: /apple\Z/ 'apple' must be at the end of the string.
What are the two uses of the metacharacter: ^ If used within a group, it means 'NOT' and when used at the start of the expression, it means the match must be at the start of the line.
What are the word boundary metacharacters and meaning? \b for a word boundary (start/end of a word). \B for NOT a word boundary.
What would be matched in: /\b\w+\b/ "abc_123 top-notch" 'abc_123', 'top' and 'notch' '_' is acceptable within a word but '-' is not.
What would be matched in: /\B\w+\B/ "This is a test." 'hi' and 'es' \B will not allow match at end of words so they must be at least 3 characters long to find anything in the word.
What defines a backreference in the query? A backreference is identified by the () brackets in the expression and this is stored for later use.
How do you refer to a backreference in the query? \1 would be the first match up to \9 for the ninth match. Some engines will match up to \99 or $1 through $9.
Use a backreference to match the phrase: apples to apples /(apples) to \1/
What is the difference between the backreference results of the two expressions when there is no 'A' to match? 1: /(A?)B/ 2: /(A)?B/ 1: The backreference will be an empty string. 2: There is no backreference at all, except if used in JavaScript.
What metacharacter do you use to specify a non-capturing group? ?:
What are the uses of the metacharacter '?'? 1) To specify a non-greedy match 2) 'Optional' character (After item referred to) 3) Non-capturing group (?:)
How do you use the non-capturing group metacharacter? Put it inside the bracket at the start. i.e.: (?:\w+)
What do each of the metacharacters for a non-capturing group signify? ? - Give this group has a different meaning : - The meaning is non-capturing
What is the metacharacter for a positive lookahead assertion? ?=
Does a positive lookahead assertion group get included in the result of a match? No, it is a zero-length item.
What is a positive lookahead assertion used for? Tests if the assertion is true or false. If it is false, the match being tested does not succeed, otherwise it continues the rest of the search. The assertion itself is not included in the grouped backreference match.
What is the syntax for a positive lookahead assertion? /(?=regex)/
What does this expression match when testing the words "seaside" and "seahorse"? /(?=seashore)sea/ Matches 'sea' in seashore but not seaside.
Are the following expressions the same or different? /(?=seashore)sea/ /sea(?=shore)/ They are the same.
What is the metacharacter for a negative lookahead assertion? ?!
Does a negative lookahead assertion group get included in the result of a match? No, it is a zero-length item.
What is a negative lookahead assertion used for? Tests that the assertion does not exist. If a match is found, the test fails and the overall search fails as well. The assertion is not included in a backreference match.
What is the syntax for use of the negative lookahead assertion? /(?!regex)/
What does the expression match when testing the words "seaside" and "seahorse"? /(?!seashore)sea/ It matches 'sea' in seaside but not seashore.
Are the following expressions the same or different? /(?!seashore)sea/ /sea(?!shore)/ They are the same.
What expression would find the last use of the word 'black' in some text? (\bblack\b)(?!.*\1) -Any time 'black' does not have 'black' somewhere after itself.
How do you specify a unicode character in a regular expression? \u0000 in JavaScript, .NET, Java, Ruby, Python \x0000 in PHP and Perl i.e. /caf\u00E9/
What is the unicode wildcard? \X (used only by PHP and perl)
What are the unicode property metacharacters? \p as in /\p{----}/ where '----' is one of the following values: Letter or L Mark or M Separator or Z Symbol or S Number or N Punctuation or P Other or C
What is the metacharacter for NOT matching property? \P as in \/P{Mark}/
What environments support the \P \p and \X metacharacters? Java, .NET, Perl, Ruby, PHP Not supported in JavaScript, Python or Unix
Created by: mcolynuck