re sub( '\ ''''this is test re sub( '\ ''''this is test or is it'or is it''this*is* *test **or*is*it?'*************preceding and following matches sometimes you want to match things if they are preceded or followed by something code description (?=matches only if followed by (?!matches only if not followed by (?<=matches only if preceded by (?<!matches only if not preceded by here is an example that matched the word the only if it is followed by catre sub( 'the(?cat''''the dog and the cat ''the dog and cathere is an example that matches the word the only if it is preceded by spacere sub( '(?<)the ''''athens is the capital 'athens is capital the following example will match the word the only if it neither preceded by and nor followed by lettersso you can use it to replace occurrences of the word thebut not occurrences of the within other words re sub( '(?<!\ )[tt]he(?!\ ''''the cat is on the lathe there 'cat is on lathe there flags there are few flags that you can use to affect the behavior of regular expression we look at few of them here (? -this is to ignore case here is an examplere sub'(? )ab ''''ab ab '(? -recall the character matches any character except newline this flag makes it match newline characterstoo