regular expressions re sub( 'abc|xyz ''''abcdefxyz abc ''*def* *in the above exampleevery time we encounter an abc or an xyzwe replace it with an asterisk matching only at the start or end sometimes you don' want to match every occurrence of somethingmaybe just the first or the last occurrence to match just the first occurrence of somethingstart the pattern off with the character to match just the last occurrenceend the pattern with the character here are some examplesre sub'^abc ''''abcdefgabc 're sub'abc''''abcdefgabc '*defgabc abcdefgescaping special characters we have seen that and have special meanings what if we need to match plus signto do souse the backslash to escape itlike \here is an examplere sub( 'ab\''''ab+ '* alsoin pattern\ represents newline just note again about raw strings--if we didn' use them for the patternsevery backslash would have to be doubled for instancer'ab\+would have to be 'ab\\backslash sequences \ matches any digitand \ matches any non-digit here is an examplere sub( '\ '''' 're sub( '\ '''' '** *** *** \ matches any letter or numberand \ matches anything else here is an examplere sub( '\ ''''this is test re sub( '\ ''''this is test or is it'or is it''***********?'this*is* *test***or*is*it*this is good way to work with words \ matches whitespaceand \ matches non-whitespace here is an example