PHP正则表达式没有连续字符,至少有一个大小写,至少有一个数字?

时间:2016-01-12 18:30:13

标签: php regex laravel

我一直在尝试制作一个匹配具有以下特征的密码的正则表达式:

  • 至少一个元音
  • 至少一个首都
  • 至少一个号码
  • 并且(最重要的)没有连续的字母或数字

密码无效的示例

  • ThisIsMyyPassword20 - (因为它重复'y'和's'而失败)
  • IMissUK20 - (失败因为它重复's')

有效密码示例

  • ThisIsMyPasword20
  • IMisUK20
  • IdontKnow20
  • IidontKnow20 - (不要失败,因为'我'和'我'不一样)

BTW:这是我实际使用的正则表达式,但是不匹配连续的字符。

regex:/^(?=.*[a-z|A-Z]\1{1})(?=.*[A-Z])(?=.*\d).+$/

谢谢大家。

2 个答案:

答案 0 :(得分:2)

您可以将此正则表达式用于满足您的所有要求:

import UIKit
import AVFoundation
import AVKit
let playerViewControllerSegue = "play";
class MyViewController: UIViewController {    
    @IBAction func playMovie(sender: UIButton) {
        self.performSegueWithIdentifier(playerViewControllerSegue, sender: self);
    }

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if (segue.identifier == playerViewControllerSegue){
            let path = NSBundle.mainBundle().pathForResource("7second", ofType:"mp4")!
            let videoURL = NSURL(fileURLWithPath: path)
            let player = AVPlayer(URL: videoURL)
            let playerViewController = segue.destinationViewController as! AVPlayerViewController
            playerViewController.player = player
            playerViewController.player?.play()
        }
    }

}

RegEx Demo

这是正则表达式分手:

^(?=.*[A-Z])(?=.*[aAeEiIoOuU])(?=.*\d)(?:([a-zA-Z\d])(?!\1))+$

答案 1 :(得分:1)

^(?=.*[aeiouAEIOU])(?=.*[A-Z])(?=.*\d)(?!.*(.)\1)[a-zA-Z0-9]+$

你可以使用它。参见演示。

https://regex101.com/r/iJ7bT6/2

相关问题