Table of Contents
回复讨论(解决方案)

正则基础题

Jun 23, 2016 pm 01:52 PM
Base regular

$url ="xxxxxxxxxxxxxxxxxxxxxx
,111111111111:
xxxxxxxxxxxxxxxxxxx";
    $preg = "/^,([0-9]+):$/im";
    preg_match_all($preg,$url,$a);
    print_r($a);    
?>

请问为何此例子在Window下无法正常匹配,而在Linux下正常匹配
是因为换行符不同 \n\r 和 \n 嘛?PHP正则基于Linux?
还是其他原因


回复讨论(解决方案)

你的理解是正确的,写成这样就通用了
$preg = "/^,([0-9]+):\s*$/im";

其实 : 就已经可以很好地判断结束了,不需要行尾 $
$preg = "/^,([0-9]+):/im";

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

Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months 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

PHP Basics Tutorial: From Beginner to Master PHP Basics Tutorial: From Beginner to Master Jun 18, 2023 am 09:43 AM

PHP is a widely used open source server-side scripting language that can handle all tasks in web development. PHP is widely used in web development, especially for its excellent performance in dynamic data processing, so it is loved and used by many developers. In this article, we will explain the basics of PHP step by step to help beginners from getting started to becoming proficient. 1. Basic syntax PHP is an interpreted language whose code is similar to HTML, CSS and JavaScript. Every PHP statement ends with a semicolon; Note

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

Learn the basics of Go language variables Learn the basics of Go language variables Mar 22, 2024 pm 09:39 PM

Go language is a statically typed, compiled language developed by Google. Its concise and efficient features have attracted widespread attention and love from developers. In the process of learning the Go language, mastering the basic knowledge of variables is a crucial step. This article will explain basic knowledge such as the definition, assignment, and type inference of variables in the Go language through specific code examples to help readers better understand and master these knowledge points. In the Go language, you can use the keyword var to define a variable, which is the format of the var variable name variable type.

Introduction to PHP Basics: How to use the echo function to output text content Introduction to PHP Basics: How to use the echo function to output text content Jul 30, 2023 pm 05:38 PM

Basic introduction to PHP: How to use the echo function to output text content. In PHP programming, you often need to output some text content to a web page. In this case, you can use the echo function. This article will introduce how to use the echo function to output text content and provide some sample code. Before starting, first make sure you have installed PHP and configured the running environment. If PHP is not installed yet, you can download the latest stable version from the PHP official website (https://www.php.net).

See all articles