Python 하위 문자열 추출 방법

1395 단어 cpython
Python 하위 문자열 추출 방법
요청: 문자열 에서
취하 다
sfsfsd345#-3sfsfsd3.4me
345#-3  
Python            :
>>> ================================ RESTART ================================
>>> def getsubstr(txt_s):
        #       
        t=txt_s
        findex=txt_s.find('#')
        s_len=len(txt_s)
        t=t[0:findex]
        dkbh=''
        bh_s=''
        for a in t:
                 #                  
                 if(a.isdigit()==True or a=='-' or a=='_'):
                     if(dkbh==''):
                          dkbh=a
                     else:
                          dkbh+=a
        s=txt_s[findex+1:findex+2]
        if(s=='-'):            
            s=txt_s[findex+1:s_len]            
            for b in s:
                if(b.isdigit()==True or b=='-' or b=='_'):
                     if(bh_s==''):
                           bh_s=b
                     else:
                           bh_s+=b
                else:
                     break
        dkbh+='#'+bh_s         
        return dkbh 
>>> print getsubstr('sfsfsd345#-3sfsfsd3.4men')
345#-3
>>> 

좋은 웹페이지 즐겨찾기