Home Backend Development PHP Tutorial 好手!请帮忙 一个正则:字符串中包含a、b、c、d、e、f这6个字母中的任意4个或5个字母

好手!请帮忙 一个正则:字符串中包含a、b、c、d、e、f这6个字母中的任意4个或5个字母

Jun 13, 2016 pm 01:18 PM
match quot str

高手!请帮忙 一个正则:字符串中包含a、b、c、d、e、f这6个字母中的任意4个或5个字母
高手!请帮忙 一个正则:字符串中包含a、b、c、d、e、f这6个字母中的任意4个或5个字母

万谢!

------解决方案--------------------
/[abcdef]{4,5}/
------解决方案--------------------
/[a-f]{4,5}/

允许重复的啊.
不允许重复的不会写正则, 只会写代码判断一下.
------解决方案--------------------
同上
------解决方案--------------------

PHP code

$str="adcdel";
function filter($str)
{
    preg_match('/^\S{6}$/',$str,$match);

    if(!empty($match[0]))
        preg_match('/[a-f]{4,5}/',$match[0],$matchs);
    return $a=isset($matchs) ? $matchs[0]:null;
}

$result = filter($str);

if($result)
{
    var_dump($result);
    echo "[[success]]";
}else{
    echo "[[failed]]";
} <div class="clear">
                 
              
              
        
            </div>
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 Jun 13, 2016 am 10:23 AM

php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决

What are the similarities and differences between __str__ and __repr__ in Python? What are the similarities and differences between __str__ and __repr__ in Python? Apr 29, 2023 pm 07:58 PM

What are the similarities and differences between __str__ and __repr__ in Python?

Python built-in type str source code analysis Python built-in type str source code analysis May 09, 2023 pm 02:16 PM

Python built-in type str source code analysis

Match matching method in java Match matching method in java Apr 28, 2023 pm 10:31 PM

Match matching method in java

How to use java Match How to use java Match Apr 18, 2023 pm 01:55 PM

How to use java Match

How to use regular expressions to match strings in Java? How to use regular expressions to match strings in Java? Apr 19, 2023 pm 02:37 PM

How to use regular expressions to match strings in Java?

Revealing the secret of str in Go language Revealing the secret of str in Go language Mar 29, 2024 am 11:27 AM

Revealing the secret of str in Go language

不用数据库来实现用户的简单的下载,代码如下,但是却不能下载,请高手找下原因,文件路劲什么的没有关问题 不用数据库来实现用户的简单的下载,代码如下,但是却不能下载,请高手找下原因,文件路劲什么的没有关问题 Jun 13, 2016 am 10:15 AM

不用数据库来实现用户的简单的下载,代码如下,但是却不能下载,请高手找下原因,文件路劲什么的没有关问题

See all articles