regex - Python Regular Expression help. Combinations -


I am trying to read from a text file and am preparing a list of seed words that start a sentence And a second list, all the adjacent words except the seed words.

The problem is that the words containing an apostrophe are split after the apostrophe and the remaining words are omitted. How will you keep them in the file?

Text contained in the file:

  Is it not a search or all correct approach to work? Or neither?   

Code:

  my_string = open ('sample.txt', 'r'). Read () starter = list (set (re.findall) (r "(? & Lt ;; [az] \ s) [az] \ w +", my_string) adjacent = redundant (r? (? Lt;; (? & Lt ;; [az] \ s)) \ W + ", my_string print (my_string)   

results:

  ['Doesn', 'look', 'to', 'work', 'sub', 'or', 'search', 'the', 'right', 'approach', 'n']  
  

With two regex it's easy:

  import re txt = "" \ \ It does not seem to work. Findall or sub-right approach? Or neither? Is not it grand? "" First_desk = set (again (''? (?: ^ | (?: [.?!] \ S)) (\ b [a-zA-z \ '] +)', txt) = rest = {In re.findall for word (r '(\ b [a-zA-z \'], txt) if the word is not printed in first_words} first_words # set (['this',' is', 'or ',' Is not ']) print rest # set (["no",' sub ',' grand ',' d ',' work '    This', 'search', 'to', 'no', 'right', 'sound', 'attitude'

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -