由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - python 正则表达式请教
相关主题
在emacs中怎么按照某种格式进行替换?正则表达式里括号的转义好乱
sed里面正则表达式匹配字符越少越好怎么写?正则表达式的问题 (转载)
perl 的问题问个正则表达式的问题
请问一个正则表达式的问题简单的perl正则表达式文本替换多个空行问题求教
急请教:用java实现解析parse一个log文件,多谢指点问个表达式
请教Regular Expression,[合集] 请问一下题目的解决答案
问个关于正则表达式的超弱智问题...Java Regular expression 请教
如何利用正则表达式提取如下字符串的前两段?请问哪有用python处理文本或者html的code
相关话题的讨论汇总
话题: xref话题: python话题: h1话题: 正则表达式话题: test
进入Programming版参与讨论
1 (共1页)
C*********m
发帖数: 213
1
向这里的高手请教一个小问题。想用python re 表达式匹配文本
[[xref:12345671|database record]][[wikipedia:AnotherLink]] test line 1
[[xref:12345672]] Test line 2
...
[[xref:12345690|another record]] test line 20
中[[xref:...]]中的内容,但是希望capture返回结果中xref:后面的数字以及|后面的
内容。
用 m = re.compile(r'\[\[xref:(\d+)(.*)\]\]')可以处理后面几行,但是第一行会把
[[wikipedia的内容也抓到一起。
r*******n
发帖数: 3020
2
because .* is greedy,
so try .*?
The following from Document of Python.
*?, +?, ??
The '*', '+', and '?' qualifiers are all greedy; they match as much text
as possible. Sometimes this behaviour isn’t desired; if the RE <.*> is
matched against '

title

', it will match the entire string, and not
just '

'. Adding '?' after the qualifier makes it perform the match in
non-greedy or minimal fashion; as few characters as possible will be matched
. Using .*? in the previous expression will

【在 C*********m 的大作中提到】
: 向这里的高手请教一个小问题。想用python re 表达式匹配文本
: [[xref:12345671|database record]][[wikipedia:AnotherLink]] test line 1
: [[xref:12345672]] Test line 2
: ...
: [[xref:12345690|another record]] test line 20
: 中[[xref:...]]中的内容,但是希望capture返回结果中xref:后面的数字以及|后面的
: 内容。
: 用 m = re.compile(r'\[\[xref:(\d+)(.*)\]\]')可以处理后面几行,但是第一行会把
: [[wikipedia的内容也抓到一起。

C*********m
发帖数: 213
3
多谢. 可以了.

text
matched

【在 r*******n 的大作中提到】
: because .* is greedy,
: so try .*?
: The following from Document of Python.
: *?, +?, ??
: The '*', '+', and '?' qualifiers are all greedy; they match as much text
: as possible. Sometimes this behaviour isn’t desired; if the RE <.*> is
: matched against '

title

', it will match the entire string, and not
: just '

'. Adding '?' after the qualifier makes it perform the match in
: non-greedy or minimal fashion; as few characters as possible will be matched
: . Using .*? in the previous expression will

1 (共1页)
进入Programming版参与讨论
相关主题
请问哪有用python处理文本或者html的code急请教:用java实现解析parse一个log文件,多谢指点
那位大侠介绍一下python的webcrawler吧请教Regular Expression,
python能检查出space是一个还是两个吗?问个关于正则表达式的超弱智问题...
parsing file in node: js or python ?如何利用正则表达式提取如下字符串的前两段?
在emacs中怎么按照某种格式进行替换?正则表达式里括号的转义好乱
sed里面正则表达式匹配字符越少越好怎么写?正则表达式的问题 (转载)
perl 的问题问个正则表达式的问题
请问一个正则表达式的问题简单的perl正则表达式文本替换多个空行问题求教
相关话题的讨论汇总
话题: xref话题: python话题: h1话题: 正则表达式话题: test