正则表达式 - 匹配 [英] regular expression - matches

查看:149
本文介绍了正则表达式 - 匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能确定给定的字符序列是否与我的正则表达式匹配,

完全?


在java中我可以做,

Pattern.compile(正则表达式).matcher(输入).matches()


这返回True / False,无论输入是否与正则表达式匹配

完全。


python中有匹配吗?

解决方案

abcd写道:


如何确定给定的字符序列是否与我的正则表达式匹配,

完全?


在java中我可以做,

Pattern.compile(正则表达式).matcher(输入).matches()


这返回True / False是否或不输入匹配正则表达式

完全。


python中有匹配吗?


>> import re
''match' 'in dir(re)



True


>> help(re.match)



功能帮助在模块sre中匹配:


匹配(模式,字符串,标志= 0)

尝试在字符串的开头应用模式,返回

a匹配对象,如果未找到匹配则为None。

有关详细信息,请参阅

http://docs.python.org/lib/module-re.html

-tkc


是的,我看到了....猜我相信我的正则表达式是准确的:)

.... b / ci得到了Matcher当我不应该,但我发现

它必须是正则表达式。


abcd写道:


我怎样才能确定给定的字符序列是否与我的正则表达式匹配,

完全?


in java for我可以做的例子,

Pattern.compile(正则表达式).matcher(输入).matches()


无论输入是否匹配,都返回True / False正则表达式

完全。


python中有匹配吗?



是的。它被称为匹配,它在重新模块中

http://docs.python.org/lib/module-re.html

Python的re.match( )从字符串的开头匹配,所以如果你想要确保整个字符串完全匹配,那么你可能希望

想要结束你的重新模式"


how can i determine if a given character sequence matches my regex,
completely?

in java for example I can do,
Pattern.compile(regex).matcher(input).matches()

this returns True/False whether or not input matches the regex
completely.

is there a matches in python?

解决方案

abcd wrote:

how can i determine if a given character sequence matches my regex,
completely?

in java for example I can do,
Pattern.compile(regex).matcher(input).matches()

this returns True/False whether or not input matches the regex
completely.

is there a matches in python?

>>import re
''match'' in dir(re)

True

>>help(re.match)

Help on function match in module sre:

match(pattern, string, flags=0)
Try to apply the pattern at the start of the string, returning
a match object, or None if no match was found.
For more info, see

http://docs.python.org/lib/module-re.html

-tkc


yea i saw that....guess I was trusting that my regex was accurate :)
....b/c i was getting a Matcher when I shouldnt have, but i found that
it must be the regex.


abcd wrote:

how can i determine if a given character sequence matches my regex,
completely?

in java for example I can do,
Pattern.compile(regex).matcher(input).matches()

this returns True/False whether or not input matches the regex
completely.

is there a matches in python?

Yes. It''s called match and it''s in the re module
(http://docs.python.org/lib/module-re.html)

Python''s re.match() matches from the start of the string, so if you
want to ensure that the whole string matches completely you''ll probably
want to end your re pattern with the "


这篇关于正则表达式 - 匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆