本文介绍了字符串特定匹配的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要一个正则表达式来匹配类似的东西
I need a regex to match something like
"4f0f30500be4443126002034"
"4f0f30500be4443126002034"
和
"4f0f30500be4443126002034>4f0f31310be4443126005578"
"4f0f30500be4443126002034>4f0f31310be4443126005578"
但不喜欢
"4f0f30500be4443126002034>4f0f31310be4443126005578>4f0f31310be4443126005579"
"4f0f30500be4443126002034>4f0f31310be4443126005578>4f0f31310be4443126005579"
推荐答案
尝试:
^[\da-f]{24}(>[\da-f]{24})?$
[\da-f]{24}
正好是 24 个字符,仅由 0-9、a-f 组成.整个模式是一个这样的数字,可选地后跟一个 > 和第二个这样的数字.
[\da-f]{24}
is exactly 24 characters consisting only of 0-9, a-f. The whole pattern is one such number optionally followed by a > and a second such number.
这篇关于字符串特定匹配的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!