I want a REGEXP to use for mysql query.
I tried this regexp and use .*
to mark anything between and the $
to mark the end of the string.
我想要一个REGEXP用于mysql查询。我尝试了这个正则表达式并使用。*标记之间的任何内容和$来标记字符串的结尾。
Battlefield.*2$
and i get this result that is normal since "2" and "2142" are both ending in "2":
我得到的结果是正常的,因为“2”和“2142”都以“2”结尾:
Battlefield 2
Battlefield :2
Battlefield: 2
Battlefield collection 2
Battlefield 2142
Battlefield : 2142
My target results is this:
我的目标结果如下:
Battlefield 2
Battlefield :2
Battlefield: 2
Battlefield collection 2
How can i get it?
我怎么才能得到它?
3 个解决方案
#1
If you don't want any other digit before the 2, then you can use
如果您不希望在2之前有任何其他数字,那么您可以使用
Battlefield.*\D2$
#2
If the numbers aren't allowed, it should be:
如果不允许这些数字,它应该是:
Battlefield[^\d]+2$
#3
$string =~ m/Battlefield[ ]?[A-Za-z]*[ ]?[:]?[ ]?2$/)
#1
If you don't want any other digit before the 2, then you can use
如果您不希望在2之前有任何其他数字,那么您可以使用
Battlefield.*\D2$
#2
If the numbers aren't allowed, it should be:
如果不允许这些数字,它应该是:
Battlefield[^\d]+2$
#3
$string =~ m/Battlefield[ ]?[A-Za-z]*[ ]?[:]?[ ]?2$/)