久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

是否有 Python 的 re.findall/re.finditer(迭代正則表達式

Is there a Perl equivalent of Python#39;s re.findall/re.finditer (iterative regex results)?(是否有 Python 的 re.findall/re.finditer(迭代正則表達式結果)的 Perl 等價物?)
本文介紹了是否有 Python 的 re.findall/re.finditer(迭代正則表達式結果)的 Perl 等價物?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

在 Python 編譯的正則表達式模式中有一個 findall 方法 執行以下操作:

In Python compiled regex patterns have a findall method that does the following:

返回所有不重疊的匹配項字符串中的模式,作為列表字符串.字符串被掃描從左到右,匹配是按找到的順序返回.如果一個或更多的群體出現在模式,返回組列表;這將是一個元組列表,如果模式有多個組.空的匹配項包含在結果中除非他們觸及另一場比賽.

Return all non-overlapping matches of pattern in string, as a list of strings. The string is scanned left-to-right, and matches are returned in the order found. If one or more groups are present in the pattern, return a list of groups; this will be a list of tuples if the pattern has more than one group. Empty matches are included in the result unless they touch the beginning of another match.

在 Perl 中執行此操作的規范方法是什么?我能想到的一個天真的算法是當搜索并用空字符串替換成功時,執行 [suite]".我希望有更好的方法.:-)

What's the canonical way of doing this in Perl? A naive algorithm I can think of is along the lines of "while a search and replace with the empty string is successful, do [suite]". I'm hoping there's a nicer way. :-)

提前致謝!

推薦答案

在你的比賽中使用 /g 修飾符.來自 perlop 手冊:

Use the /g modifier in your match. From the perlop manual:

/g"修飾符指定全局模式匹配——即在字符串中盡可能多地匹配.它的行為方式取決于上下文.在列表上下文中,它返回與正則表達式中的任何捕獲括號匹配的子字符串列表.如果沒有括號,則返回所有匹配字符串的列表,就好像整個模式都有括號一樣.

The "/g" modifier specifies global pattern matching--that is, matching as many times as possible within the string. How it behaves depends on the context. In list context, it returns a list of the substrings matched by any capturing parentheses in the regular expression. If there are no parentheses, it returns a list of all the matched strings, as if there were parentheses around the whole pattern.

在標量上下文中,每次執行 "m//g" 都會找到下一個匹配項,如果匹配則返回 true,如果沒有進一步匹配則返回 false.可以使用 pos() 函數讀取或設置最后一次匹配后的位置;請參閱 perlfunc 中的pos".失敗的匹配通常會將搜索位置重置為字符串的開頭,但您可以通過添加/c"修飾符來避免這種情況(例如m//gc").修改目標字符串也會重置搜索位置.

In scalar context, each execution of "m//g" finds the next match, returning true if it matches, and false if there is no further match. The position after the last match can be read or set using the pos() function; see "pos" in perlfunc. A failed match normally resets the search position to the beginning of the string, but you can avoid that by adding the "/c" modifier (e.g. "m//gc"). Modifying the target string also resets the search position.

這篇關于是否有 Python 的 re.findall/re.finditer(迭代正則表達式結果)的 Perl 等價物?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Troubles while parsing with python very large xml file(使用 python 解析非常大的 xml 文件時出現問題)
Find all nodes by attribute in XML using Python 2(使用 Python 2 在 XML 中按屬性查找所有節點)
Python - How to parse xml response and store a elements value in a variable?(Python - 如何解析 xml 響應并將元素值存儲在變量中?)
How to get XML tag value in Python(如何在 Python 中獲取 XML 標記值)
How to correctly parse utf-8 xml with ElementTree?(如何使用 ElementTree 正確解析 utf-8 xml?)
Parse XML from URL into python object(將 XML 從 URL 解析為 python 對象)
主站蜘蛛池模板: 亚洲精品国产电影 | 亚洲精品一区二区三区在线 | 亚洲综合色视频在线观看 | 成人激情视频免费观看 | 一级一级一级毛片 | 国产91精品久久久久久久网曝门 | 国产精品视频一二三区 | 日韩黄色av | 亚洲视频一区在线播放 | 国产亚洲一区二区精品 | av在线免费播放 | 四虎网站在线观看 | 成人在线视频网站 | 九九精品网 | 七七婷婷婷婷精品国产 | 福利视频一二区 | 国产精品揄拍一区二区 | 亚洲久久 | 亚洲精品国产成人 | 国产男女猛烈无遮掩视频免费网站 | 国产伦精品 | 国产影音先锋 | 一区二区三区精品视频 | 91av在线视频观看 | 欧美成人一区二免费视频软件 | aaa大片免费观看 | 亚洲精品视频在线 | 成人在线网 | 中文在线а√在线8 | 日韩福利片 | 精品国产91亚洲一区二区三区www | 成人在线中文字幕 | 碰碰视频 | 国产电影一区二区 | 91av在线视频观看 | 亚洲精品久久久久久久久久吃药 | 亚洲精品一区二区在线观看 | 在线免费观看毛片 | 国产精品高潮呻吟久久 | 国产伦精品一区二区三区精品视频 | 日本一区二区电影 |