Advertisement
Guest User

Untitled

a guest
Aug 20th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. #This is my long string object I would like to count all substring in:
  2. >>>type(contents2)
  3. <class 'str'>
  4.  
  5. #This is my regular expression substring I want to count the instances of, any size lengths of N's
  6. >>>import re
  7. >>> nstring = re.compile(r"[^N][N+][^N]")
  8.  
  9. #Search through the string and count the number of times the substring appears
  10. >>>len(re.findall(nstring, contents2))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement