fork(1) download
  1. import re
  2.  
  3. regex_whitespace = r'(\w+)\s+(\w+)\b'
  4. pattern = re.compile(regex_whitespace) # this I just added after reviewing other related questions
  5. labels_ls = ['word <= 0.01', 'word_two <= 0.23', 'word three <= 0.01']
  6. # Loop through labels_ls to find any ngrams whitespace separated labels (i.e gilt maximal)
  7. for i in labels_ls:
  8. if re.match(regex_whitespace, i):
  9. # replace the whitespace with a '_' to form gilt*maximal
  10. new_string = re.sub(pattern, r'\1_\2', i)
  11. print('new string: ', new_string)
Success #stdin #stdout 0.02s 27712KB
stdin
Standard input is empty
stdout
new string:  word_three <= 0.01