Regular expression for matching non-whitespace in Python

后端 未结 4 1791
刺人心
刺人心 2021-01-20 01:03

I want to use re.search to extract the first set of non-whitespace characters. I have the following pseudoscript that recreates my problem:

#!/usr/b         


        
4条回答
  •  梦谈多话
    2021-01-20 01:49

    Replace your re.search as below, \S finds non-whitespace character, and + searches for one or more times. Python starts to search from first character.

    import re
    line = "STARC-1.1.1.5             ConsCase    WARNING    Warning"
    m = re.search('\S+',line)
    print(m.group(0))
    

提交回复
热议问题