正则纠结中…该如何处理
正则纠结中……
[^\f\n\r\t\v] \S ,是否真的等同?
去掉[^\f\n\r\t\v],$s2中的空格去不了,加上以后,什么都不匹配……
- PHP code
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --> function checkString($str){ //去掉非英文以外的其他语言包括乱码、空格。需要英文加特殊符号的内容 if(preg_match("/^ [ [:alnum:] [:space:] [:punct:] [^\f\n\r\t\v]]+ $/x",$str)){ return $str; }else{ echo "含非匹配项"; } } $s1 = "!!!!!!!"; $s2 = "1 1 1 1 1 1 1"; $s3 = "123asd"; echo checkString($s1)."<br>"; echo checkString($s2)."<br>"; echo checkString($s3)."<br>"; /*输出 含非匹配项 含非匹配项 含非匹配项 */
还有,将[]改成(),再加个第三参数$res,没有获取到结果集。如:
- PHP code
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --> if(preg_match("/^( [ [:alnum:] [:space:] [:punct:]]+ )$/x","11111111",$res)){ print_r($res); }else{ echo "含非匹配项"; //输出在这里 }
------解决方案--------------------
[^\f\n\r\t\v] \S ,是否真的等同?
不等同!
\S 表示非空白字符,空格也是空白字符,[^\f\n\r\t\v]众位包括
------解决方案--------------------
什么意思?去除其它只保留英文字符?
------解决方案--------------------
- PHP code
if(preg_match("/^( [^\s]+ )/x","1 1 1 11111",$res)){ print_r($res); }else{ echo "含非匹配项"; } <br><font color="#e78608">------解决方案--------------------</font><br>你按space键位的那个空格你都没包含进来,恰巧你的串里的空格是space那个,有点晕了吧,呵呵。<br>ascii码<br>--------------<br>space -> 32<br>\n -> 10<br>\t -> 9<br>\f -> 12<br>\r -> 13<br>\v -> 11<br><br> <br><font color="#e78608">------解决方案--------------------</font><br>你加x修正符然后正则里还有空格符,这不是白用x了么?<br>
- PHP code
if(preg_match("/([^ \f\n\r\t\v]+)/","1 2 3 4444",$res)) { print_r($res) } <br><font color="#e78608">------解决方案--------------------</font><br>第一个问题就说你想留下什么吧<br>第二个:
- PHP code
if(preg_match('/(.)\1\1/',$str,$matches)) echo '不能有连续三位相同'; <br><font color="#e78608">------解决方案--------------------</font><br>
------解决方案--------------------
嗯,然后加上判断是否有重复字符的,可能必须得循环了,一句正则就出来你要的结果我暂时没想到有什么方法。
------解决方案--------------------
- PHP code
$s = "1 2 3 4444"; //过滤空格的正则 echo preg_replace('/\s+/', '', $s);//1234444 //过滤重复字符的正则 echo preg_replace('/(.)\\1+/', '$1', $s);//1 2 3 4 //和在一起 echo preg_replace(array('/(\s+)/', '/(.)\\1+/'), array('', '$1'), $s);//1234 <br><font color="#e78608">------解决方案--------------------</font><br>preg_match_all("/([\s*@#_)-])|((.)\\3+)/", $psw, $r);<br>print_r($r);<br><br><br>Array<br>(<br> [0] => Array<br> (<br> [0] => <br> [1] => <br> [2] => <br> [3] => <br> [4] => 11<br> [5] => <br> [6] => 11<br> [7] => <br> [8] => 11<br> [9] => <br> [10] => * <div class="clear"> </div>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety

Why Snipping Tool Not Working on Windows 11 Understanding the root cause of the problem can help find the right solution. Here are the top reasons why the Snipping Tool might not be working properly: Focus Assistant is On: This prevents the Snipping Tool from opening. Corrupted application: If the snipping tool crashes on launch, it might be corrupted. Outdated graphics drivers: Incompatible drivers may interfere with the snipping tool. Interference from other applications: Other running applications may conflict with the Snipping Tool. Certificate has expired: An error during the upgrade process may cause this issu simple solution. These are suitable for most users and do not require any special technical knowledge. 1. Update Windows and Microsoft Store apps

In today's era of rapid technological development, programming languages are springing up like mushrooms after a rain. One of the languages that has attracted much attention is the Go language, which is loved by many developers for its simplicity, efficiency, concurrency safety and other features. The Go language is known for its strong ecosystem with many excellent open source projects. This article will introduce five selected Go language open source projects and lead readers to explore the world of Go language open source projects. KubernetesKubernetes is an open source container orchestration engine for automated

"Go Language Development Essentials: 5 Popular Framework Recommendations" As a fast and efficient programming language, Go language is favored by more and more developers. In order to improve development efficiency and optimize code structure, many developers choose to use frameworks to quickly build applications. In the world of Go language, there are many excellent frameworks to choose from. This article will introduce 5 popular Go language frameworks and provide specific code examples to help readers better understand and use these frameworks. 1.GinGin is a lightweight web framework with fast

Part 1: Initial Troubleshooting Steps Checking Apple’s System Status: Before delving into complex solutions, let’s start with the basics. The problem may not lie with your device; Apple's servers may be down. Visit Apple's System Status page to see if the AppStore is working properly. If there's a problem, all you can do is wait for Apple to fix it. Check your internet connection: Make sure you have a stable internet connection as the "Unable to connect to AppStore" issue can sometimes be attributed to a poor connection. Try switching between Wi-Fi and mobile data or resetting network settings (General > Reset > Reset Network Settings > Settings). Update your iOS version:

With the development of the Internet and the advancement of information technology, the era of big data has arrived, and fields such as data analysis and machine learning have also been widely used. In these fields, task scheduling is an inevitable problem. How to achieve efficient task scheduling is crucial to improving efficiency. In this article, we will introduce how to use Golang's web framework Echo framework to implement distributed task scheduling. 1. Introduction to the Echo framework Echo is a high-performance, scalable, lightweight GoWeb framework. It is based on HTTP

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

Laravel is a popular PHP framework that is highly scalable and efficient. It provides many powerful tools and libraries that allow developers to quickly build high-quality web applications. Among them, LaravelEcho and Pusher are two very important tools through which WebSockets communication can be easily implemented. This article will detail how to use these two tools in Laravel applications. What are WebSockets? WebSockets
