检查两个字符的正则表达式
我想检查是否 值为“H”或“T” 否则它可以是“H” 或者它可以是“T” 或者“H”和“T”
这一切都存储在一个数组中
我正在使用这个正则表达式来检查这两个单词。
$combo = preg_match('[HT]',strtoupper($_REQUEST['combo']));
如果值为 HT 它会给我成功。如果我只输入“H”或“T”...或重复出现“H”或“T”,则它不满足上面的代码。
希望这可以帮助您理解...一个简单的抛硬币游戏,有两种可能的结果:“H”- 正面和“T”- 反面...用户总共可以玩 9 轮... $combo 正在存储这个组合只包含 H 和 T...我正在从我得到的 url 检查 php 调用,例如:- www.domain-name.com/submit_combo_predisc.php/?prefix=p&uid=username&txn=9574621083&combo=HH H&k=29c3550e430723e5c61a66bd03ba4ff5....
这里用户获得了三个正确的输入,他赢得了一定的金额正确组合三个组合。 url 如果我输入“HH4”而不是“HHH”,它仍然显示您正确地获得了三个组合,并且为用户提供了一定的金额来获得正确的三个组合......这实际上是错误的......因为传递的值是“HH4”...不是“HHH”。 用户实际上可以滥用该网址来赢得无限金额......
I want to check if the
value is 'H' or 'T'
or else it can be 'H'
orelse it can be 'T'
or both 'H' and 'T'
this all is stored in an array
I'm using this regular expression to check these two words.
$combo = preg_match('[HT]',strtoupper($_REQUEST['combo']));
it gives me success if the value is HT . If i put just 'H' or 'T'...or recurring 'H' or 'T' it doesn't satisfy the code above.
hope this might help you understand...a simple coin toss game which has two possible out comes 'H'- heads and 'T'-tails.....User can play 9 rounds in all... $combo is storing this combination which contains H and T only...I'm checking a php call here from url that I got eg:- www.domain-name.com/submit_combo_predisc.php/?prefix=p&uid=username&txn=9574621083&combo=HHH&k=29c3550e430723e5c61a66bd03ba4ff5....
here user has got three inputs right and he wins certain amount for getting three combination right.in the url if I enter 'HH4' instead of 'HHH' it still displays u got three combo right and the user is given certain amount for getting the three combinations right....which is actually wrong....because the value passed are 'HH4'...n not 'HHH'.
User can actually misuse the url to win unlimited amount....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这匹配 H、T 和 HT。
如果你也想搭配TH,
是更好的选择。
this matches H, T and HT.
if you want to match TH too,
is the better choice.
正则表达式必须是
这允许以下值:“H”、“T”、“HT”、“TH”、“HH”和“TT”,但不能有其他值!
the regex must be
This allows following values: 'H', 'T', 'HT', 'TH', 'HH' and 'TT' but nothing else!
您想为此使用量词。
{1,2}
可以工作:请注意,您的正则表达式也缺少分隔符。这就是为什么它只匹配
HT
- 因为方括号被解释为分隔符而不是字符组。似乎您真正想要的(但从未说过)是计算
H
和T
的数量。那么更简单的方法是:You want to use a quantifier for that.
{1,2}
would work:Note that your regex was also lacking delimiters. That's why it only ever matched
HT
- because the square brackets were interpreted as delimiters rather than as character group.Seems what you actually want (but never said) was to count the number of
H
s andT
s. Then the simpler approach would be: