Regular expression for matching non-whitespace in Python

后端 未结 4 1741
刺人心
刺人心 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:33

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

    The re.search returns the match, so use the alphabets and numbers and print the match as mentioned in the code. If you print only the variable it prints it as match 1. Hope this answers your question

    m = re.search('[A-Z].+[0-9]',line)
    

    Changing the re.search to the capital letters will find from CAPS A to Z, vice vers if you change it to small letters as

    m = re.search('[a-z].+[0-9]',line)
    

    it will find only small letters, sometimes you should highlight the symbols too, to search from it or to search upto the characters before that symbol.

提交回复
热议问题