id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

regexp_search


A "regular expression" is a pattern used to match against strings of text. For example, just like the "find" function in your word processor or browser, regexp_search("test", "This is a test") returns True, because the pattern "test" appears in the text. But a regular expression describes not just a literal sequence of characters, but rather an expression that could match different sequences. For example, the regular expression "t.e" means a t followed by any character, followed by a e, so it matches "the" and "tee" and "t@e", but not "tea". There are four special characters in patterns: "^", "$", "*", and ".". The rules for a pattern match are: (1) the empty pattern matches any text. (2) if the pattern starts with "^" then the match must start at the start of text (otherwise the match can start anywhere). If the pattern ends in "$", then the match must go up to the end of the text. (We promise that the "^" and "$" will only appear as the first or last character of the pattern, respectively.) If the pattern contains a ".", then that matches any character. And if the pattern contains some character c followed by a "*", then that matches zero or more instances of the character (the character can be the wildcard character ".", or a regular character). regexp_search(pattern, text) returns true if the pattern matches according to these rules.


regexp_search('hel*o', 'hello, world') → True
regexp_search('hel*o', 'hellllllllllp') → False
regexp_search('^hel*o', 'well, hello') → False

...Save, Compile, Run (ctrl-enter)

def regexp_search(pattern, text):

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Python Help

Difficulty: 650 Post-solution available

Copyright Nick Parlante 2017 - privacy