String Metods and Regex Metacharacters
String Metods and Regex Metacharacters
Method Description
capitalize() Converts the first character to upper case
casefold() Converts string into lower case
center() Returns a centered string
count() Returns the number of times a specified value occurs in a string
encode() Returns an encoded version of the string
endswith() Returns true if the string ends with the specified value
expandtabs() Sets the tab size of the string
Searches the string for a specified value and returns the position of
find() where it was found
format() Formats specified values in a string
format_map() Formats specified values in a string
Searches the string for a specified value and returns the position of
index() where it was found
isalnum() Returns True if all characters in the string are alphanumeric
isalpha() Returns True if all characters in the string are in the alphabet
isdecimal() Returns True if all characters in the string are decimals
isdigit() Returns True if all characters in the string are digits
isidentifier() Returns True if the string is an identifier
islower() Returns True if all characters in the string are lower case
isnumeric() Returns True if all characters in the string are numeric
isprintable() Returns True if all characters in the string are printable
isspace() Returns True if all characters in the string are whitespaces
istitle() Returns True if the string follows the rules of a title
isupper() Returns True if all characters in the string are upper case
join() Joins the elements of an iterable to the end of the string
ljust() Returns a left justified version of the string
lower() Converts a string into lower case
lstrip() Returns a left trim version of the string
maketrans() Returns a translation table to be used in translations
partition() Returns a tuple where the string is parted into three parts
Returns a string where a specified value is replaced with a specified
replace() value
Searches the string for a specified value and returns the last position
rfind() of where it was found
Searches the string for a specified value and returns the last position
rindex() of where it was found
rjust() Returns a right justified version of the string
rpartition() Returns a tuple where the string is parted into three parts
rsplit() Splits the string at the specified separator, and returns a list
rstrip() Returns a right trim version of the string
split() Splits the string at the specified separator, and returns a list
splitlines() Splits the string at line breaks and returns a list
startswith() Returns true if the string starts with the specified value
strip() Returns a trimmed version of the string
swapcase() Swaps cases, lower case becomes upper case and vice versa
title() Converts the first character of each word to upper case
translate() Returns a translated string
upper() Converts a string into upper case
zfill() Fills the string with a specified number of 0 values at the beginning
Page 1
Sheet2
character Description
[] A set of characters
Signals a special sequence (can also be used to escape
\ special characters)
() Any character (except newline character)
^ Starts with
$ Ends with
* Zero or more occurrences
+ One or more occurrences
{} Exactly the specified number of occurrences
| Either or
METACHARACTERS
Page 2
Sheet3
Set Description
[abc] Returns a match where one of the specified characters are present
[a-d] Returns a match for any lower case character, alphabetically between a and d
[^a] Returns a match for any character EXCEPT a
[0123] Returns a match where any of the specified digits (0, 1, 2, or 3) are present
[0-9] Returns a match for any digit between 0 and 9
[0-5][0-9] Returns a match for any two-digit numbers from 00 and 59
[a-zA-Z] Returns a match for any character alphabetically between a and z, lower case OR upper case
SETS
Page 3
Sheet4
Character Description
Returns a match if the specified characters are at the beginning
\A of the string
Returns a match where the specified characters are at the
\b beginning or at the end of a word
Returns a match where the specified characters are present,
\B but NOT at the beginning (or at the end) of a word
Returns a match where the string contains digits (numbers from
\d 0-9)
\D Returns a match where the string DOES NOT contain digits
Returns a match where the string contains a white space
\s character
Returns a match where the string DOES NOT contain a white
\S space character
Returns a match where the string contains any word characters
(characters from a to Z, digits from 0-9, and the underscore _
\w character)
Returns a match where the string DOES NOT contain any word
\W characters
Returns a match if the specified characters are at the end of the
\Z string
SEQUENCES
Page 4