Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial 正则问题来一发

正则问题来一发

Jun 23, 2016 pm 01:52 PM
regular

问了下老徐,不过老徐最近很忙显然消息也没时间看,那就发出来给大家研究研究

能匹配以下两种情况,不是其中之一... 

http://www.uploadfr.com/images/2014/03/20/204417dydmmeowem3mlnl0.jpg.thumb0608f2.jpg http://www.uploadfr.com/images/2014/03/20/204417dydmmeowem3mlnl0.jpg


回复讨论(解决方案)

/^http://www.uploadfr.com/images/\d{4}/(\d{2}/){2}\S*.jpg$/

<?php$str1 = 'http://www.uploadfr.com/images/2014/03/20/204417dydmmeowem3mlnl0.jpg.thumb0608f2.jpg';$str2 = 'http://www.uploadfr.com/images/2014/03/20/204417dydmmeowem3mlnl0.jpg';$pattern = '/^http:\/\/www\.uploadfr\.com\/images\/(\d{4})\/(\d{2})\/(\d{2})\/([a-z0-9]+)\.(jpg|png|gif|jpeg)(\.thumb([a-z0-9]{6})\.\\5)?$/';preg_match($pattern, $str1, $match1);preg_match($pattern, $str2, $match2);print_r($match1);print_r($match2);
Copy after login

看看是不是这样,因为不知道你要匹配的精度,先写了一个。

$content=<<<TXT字字字字字字字字字字字字字字字字字字字字字字字字字字字字字字字字字字字字字字字字字字字字字字字字http://www.uploadfr.com/images/2014/03/20/204417dydmmeowem3mlnl0.jpg.thumb0608f2.jpg字字字字字字字字字字字字字字字字http://www.uploadfr.com/images/2014/03/20/204417dydmmeowem3mlnl0.jpg字字字字字字字字字字字字字字字字TXT;preg_match_all('/http:\/\/www.uploadfr.com\/images\/\d{4}\/\d{2}\/\d{2}\/\d{6}.*?jpg(\.thumb[a-z0-9]{6}\.jpg)?/si', $content, $matches);print_r($matches[0]);
Copy after login

不知道dydmmeowem3mlnl0这个你需要匹配吗?如果要改成这样
preg_match_all('/http:\/\/www.uploadfr.com\/images\/\d{4}\/\d{2}\/\d{2}\/\d{6}[a-z0-9]{16}\.jpg(\.thumb[a-z0-9]{6}\.jpg)?/si', $content, $matches);

1、我没有收到你的消息
2、这样的规则串 '#http://\S+\.jpg\b#' 不可以吗

1、我没有收到你的消息
2、这样的规则串 '#http://\S+\.jpg\b#' 不可以吗


他肯定有特殊要求,又没说明白。
发个问题都没发清楚,该批评。

应该没有特别要求,只不过第一种情况多了一段以 jpg 结尾的串
这样就不能使用非贪婪模式了


1、我没有收到你的消息
2、这样的规则串 '#http://\S+\.jpg\b#' 不可以吗


他肯定有特殊要求,又没说明白。
发个问题都没发清楚,该批评。

表示关注一下

我都忘记发过这个帖子了。罪过罪过...

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 AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

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)

How to replace a string starting with something with php regular expression How to replace a string starting with something with php regular expression Mar 24, 2023 pm 02:57 PM

PHP regular expressions are a powerful tool for text processing and conversion. It can effectively manage text information by parsing text content and replacing or intercepting it according to specific patterns. Among them, a common application of regular expressions is to replace strings starting with specific characters. We will explain this as follows

How to match multiple words or strings using Golang regular expression? How to match multiple words or strings using Golang regular expression? May 31, 2024 am 10:32 AM

Golang regular expressions use the pipe character | to match multiple words or strings, separating each option as a logical OR expression. For example: matches "fox" or "dog": fox|dog matches "quick", "brown" or "lazy": (quick|brown|lazy) matches "Go", "Python" or "Java": Go|Python |Java matches words or 4-digit zip codes: ([a-zA

How to use regular expressions to remove Chinese characters in php How to use regular expressions to remove Chinese characters in php Mar 03, 2023 am 10:12 AM

How to remove Chinese in PHP using regular expressions: 1. Create a PHP sample file; 2. Define a string containing Chinese and English; 3. Use "preg_replace('/([\x80-\xff]*)/i', '',$a);" The regular method can remove Chinese characters from the query results.

How to use regular matching to remove html tags in php How to use regular matching to remove html tags in php Mar 21, 2023 pm 05:17 PM

In this article, we will learn how to remove HTML tags and extract plain text content from HTML strings using PHP regular expressions. To demonstrate how to remove HTML tags, let's first define a string containing HTML tags.

Sharing tips on using PHP regular expressions to implement Chinese replacement function Sharing tips on using PHP regular expressions to implement Chinese replacement function Mar 24, 2024 pm 05:57 PM

Sharing tips on using PHP regular expressions to implement the Chinese replacement function. In web development, we often encounter situations where Chinese content needs to be replaced. As a popular server-side scripting language, PHP provides powerful regular expression functions, which can easily realize Chinese replacement. This article will share some techniques for using regular expressions to implement Chinese substitution in PHP, and provide specific code examples. 1. Use the preg_replace function to implement Chinese replacement. The preg_replace function in PHP can be used

How to verify if a URL is HTTPS protocol using PHP regex How to verify if a URL is HTTPS protocol using PHP regex Jun 24, 2023 am 08:16 AM

Website security has attracted more and more attention, and using the HTTPS protocol to ensure the security of data transmission has become an important part of current website development. In PHP development, how to use regular expressions to verify whether the URL is HTTPS protocol? here we come to find out. Regular expression Regular expression is an expression used to describe rules. It is a powerful tool for processing text and is widely used in text matching, search and replacement. In PHP development, we can use regular expressions to match http in the URL

An in-depth explanation of PHP regular expression escaping An in-depth explanation of PHP regular expression escaping Mar 21, 2023 pm 02:52 PM

​Regular expressions are a powerful tool for matching strings and can facilitate string manipulation. However, in the process of writing regular expressions, sometimes you may need to match some special characters, such as "\", "|", "{", etc. These characters have special meanings in regular expressions and need to be escaped.

PHP regular replacement examples: quickly master replacement skills PHP regular replacement examples: quickly master replacement skills Feb 29, 2024 pm 06:33 PM

PHP regular replacement examples: quickly master replacement skills. With the development of the Internet, website development has become more and more common. In website development, it is often necessary to replace strings, and regular expressions are a very powerful tool that can quickly search and replace strings. This article will introduce how to use regular expressions in the PHP language to perform replacement operations, and provide specific code examples to help readers quickly master replacement techniques. 1.preg_replace function in PHP, you can use preg

See all articles