匹配字符串中任意位置的模式? [英] Match pattern anywhere in string?
本文介绍了匹配字符串中任意位置的模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想匹配以下模式:
Exxxx49 (where x is a digit 0-9)
例如E123449abcdefgh
、abcdefE123449987654321
都是有效的.即,我需要匹配字符串中任意位置的模式.
For example, E123449abcdefgh
, abcdefE123449987654321
are both valid. I.e., I need to match the pattern anywhere in a string.
我正在使用:
^*E[0-9]{4}49*$
但它只匹配E123449
.
如何在模式之前或之后允许任意数量的字符?
How can I allow any amount of characters in front or after the pattern?
推荐答案
删除 ^
和 $
以搜索字符串中的任意位置.
Remove the ^
and $
to search anywhere in the string.
在您的情况下,*
可能不是您想要的;E[0-9]{4}49
应该足够了.这将在字符串中的任何位置找到一个 E,后跟四位数字,后跟一个 4 和一个 9.
In your case the *
are probably not what you intended; E[0-9]{4}49
should suffice. This will find an E, followed by four digits, followed by a 4 and a 9, anywhere in the string.
这篇关于匹配字符串中任意位置的模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文