pyparsing使用

1935 ワード

from pyparsing  import Word ,Literal,Suppress,ParseResults,nums,alphanums,Combine,Keyword,Optional,oneOf
Q:      ,      case   “c:15865844”  “ctimes: 15865844”      。
str1 = "I/f( 5255): u:-3499006, c:15865844, k:0,RealUs:63562386362, you:63581751212"
str2 = "I/f( 5255): u:-3499006, ctimes:15865844, k:0,RealUs:63562386362, you:63581751212"


pat = (Literal('c:')|Literal('ctimes:')) + Word(nums)
print pat.searchString(str1)
print pat.searchString(str2)
 
  
    “ ”   。    (exp1|exp2),           ,   ,    。
 
  
 
  
 
  
 
  
oneOf()    :oneOf(para),    para            list
l = ['a','b']
oneOf(l) #       'a'   'b'
str = 'a' + ' ' + 'b'
oneOf(str) #       'a'   'b'