亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫(kù)
最近訪問(wèn)板塊 發(fā)新帖
查看: 3379 | 回復(fù): 2
打印 上一主題 下一主題

python正則表達(dá)式問(wèn)題 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2014-01-13 16:50 |只看該作者 |倒序?yàn)g覽
程序如下:
_regexp_compile_cache = {}

def Search(pattern, s):
  """Searches the string for the pattern, caching the compiled regexp."""
  if pattern not in _regexp_compile_cache:
    _regexp_compile_cache[pattern] = sre_compile.compile(pattern)
  return _regexp_compile_cache[pattern].search(s)

match_point = Search(r'[^(]+([^,]*)\*([^,]*)', realine)

realine為某行的內(nèi)容,程序原意為取某行含有“*”但不含有“(”的那一行,但試了下下面的兩個(gè)例子
bool DimeterOmc::writeLog( int code_id, const char* log_desc, ... )
typedef bool (*DYNCHECKFUNC)();
發(fā)現(xiàn)都會(huì)被取出來(lái),想問(wèn)下哪里是不是寫錯(cuò)了呢???

論壇徽章:
33
榮譽(yù)會(huì)員
日期:2011-11-23 16:44:17天秤座
日期:2014-08-26 16:18:20天秤座
日期:2014-08-29 10:12:18丑牛
日期:2014-08-29 16:06:45丑牛
日期:2014-09-03 10:28:58射手座
日期:2014-09-03 16:01:17寅虎
日期:2014-09-11 14:24:21天蝎座
日期:2014-09-17 08:33:55IT運(yùn)維版塊每日發(fā)帖之星
日期:2016-04-17 06:23:27操作系統(tǒng)版塊每日發(fā)帖之星
日期:2016-04-18 06:20:00IT運(yùn)維版塊每日發(fā)帖之星
日期:2016-04-24 06:20:0015-16賽季CBA聯(lián)賽之天津
日期:2016-05-06 12:46:59
2 [報(bào)告]
發(fā)表于 2014-01-14 08:33 |只看該作者
回復(fù) 1# wuzen007
  1. r'[^(]+([^,]*)\*([^,]*)'
  2. '[^(]+'
  3. [color=Red]'([^,]*)'[/color]
  4. '\*'
  5. '[color=Red]([^,]*)[/color]'
復(fù)制代碼
是紅色部分匹配了 '(' 了.

如果你想不要 '(', 試試把紅色的改成 [^,(] 這樣

論壇徽章:
0
3 [報(bào)告]
發(fā)表于 2014-01-14 18:15 |只看該作者
兩個(gè)問(wèn)題:
1.要匹配整行,是不是用match更合適。
match從字符串的開頭開始匹配,如果開頭位置沒有匹配成功,就算失敗了;而search會(huì)跳過(guò)開頭,繼續(xù)向后尋找是否有匹配的字符串。

2.正則表達(dá)式中:r'[^(]+([^,]*)\*([^,]*)' 中的[^,]是不是又包含了(
用這個(gè)試試:r'[^(]*\*+[^(]*'
  1. import re

  2. _regexp_compile_cache = {}

  3. def Search(pattern, s):
  4.   """Searches the string for the pattern, caching the compiled regexp."""
  5.   if pattern not in _regexp_compile_cache:
  6.     _regexp_compile_cache[pattern] = re.compile(pattern)
  7.   return _regexp_compile_cache[pattern].match(s)

  8. readline = 'bool DimeterOmc::writeLog( int code_id, const char* log_desc, ...)'
  9. #            typedef bool (*DYNCHECKFUNC)();'''
  10. match_point = Search(r'[^(]*\*+[^(]*', readline)

  11. print match_point.group(0)
復(fù)制代碼
您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國(guó)互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過(guò)ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP