Home Backend Development PHP Tutorial 关于php正则表达式的两点备注_PHP

关于php正则表达式的两点备注_PHP

Jun 01, 2016 pm 12:34 PM
bar pattern about

正则表达式

 
severaltipsaboutRegularExpressions
  1.processfor"greedy"
  Bydefault,thequantifiersare"greedy",thatis,they
  matchasmuchaspossible(uptothemaximumnumberofper-
  mittedtimes),withoutcausingtherestofthepatternto
  fail.Theclassicexampleofwherethisgivesproblemsisin
  tryingtomatchcommentsinCprograms.Theseappearbetween
  thesequences/*and*/andwithinthesequence,individual
  *and/charactersmayappear.AnattempttomatchCcom-
  mentsbyapplyingthepattern
  
  /\*.*\*/
  
  tothestring
  
  /*firstcommand*/notcomment/*secondcomment*/
  
  fails,becauseitmatchestheentirestringduetothe
  greedinessofthe.*item.
  
  However,ifaquantifierisfollowedbyaquestionmark,
  thenitceasestobegreedy,andinsteadmatchestheminimum
  numberoftimespossible,sothepattern
  
  /\*.*?\*/
  

 


  小结:
  ?与/U有类似功能,但同时出现彼此抵消
  
  如下:
     $a="asdf/*asdfaldsfasdf*/asfdasldf;kfldsj*/asfddsaf";
  $pattern="/\/\*.*?\*\//";
  //$pattern="/\/\*.*\*\//U";
  //$pattern="/\/\*.*?\*\//U";
  preg_match($pattern,$a,$match);
  print_r($match);
  ?>
  
  2.Assertions
  \w+(?=;)
  
  matchesawordfollowedbyasemicolon,butdoesnotinclude
  thesemicoloninthematch,and
  
  foo(?!bar)
  
  matchesanyoccurrenceof"foo"thatisnotfollowedby
  "bar".Notethattheapparentlysimilarpattern
  
  小结:
  (?!)只前向判断匹配,如bar(?!foo),而(?!foo)bar没有意义
  (?

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

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 completely uninstall Xbox Game Bar in Win11? Share how to uninstall Xbox Game Bar How to completely uninstall Xbox Game Bar in Win11? Share how to uninstall Xbox Game Bar Feb 10, 2024 am 09:21 AM

How to completely uninstall Win11XboxGameBar? Xbox GameBar is the game platform that comes with the system. It provides tools for game recording, screenshots and social functions. However, it takes up a lot of memory and is not easy to uninstall. Some friends want to uninstall it, but there is no way. How to completely uninstall it, let me introduce it to you below. Method 1. Use Windows Terminal 1. Press the [Win+X] key combination, or [right-click] click [Windows Start Menu] on the taskbar, and select [Terminal Administrator] from the menu item that opens. 2. User Account Control window, do you want to allow this app to make changes to your device? Click [Yes]. 3. Execute the following command: Get-AppxP

'Touch ID Login' stuck on Mac Touch Bar? This is the fix 'Touch ID Login' stuck on Mac Touch Bar? This is the fix Apr 15, 2023 pm 12:04 PM

Fix "TouchID Login" Issue on MacTouchBar Using Safari Icon Force the Touch Bar to restart will fix the issue: Open ActivityMonitor on your Mac, which is located in the /Applications/Utilities folder, or you can use Spotlight by pressing Command+Spacebar and Type ActivityMonitor and go back to launch it Use the search function of Activity Monitor and search for "Touch" Select "TouchBarServer" and then click the (X) Exit button in the Activity Monitor toolbar Select "Force Quit" to force

Using Pattern.compile method in Java Using Pattern.compile method in Java Feb 18, 2024 pm 09:04 PM

Usage of Pattern.compile function in Java The Pattern.compile function in Java is a method used to compile regular expressions. Regular expression is a powerful string matching and processing tool that can be used to find, replace, verify strings and other operations. The Pattern.compile function allows us to compile a string pattern into a Pattern object, which can then be used to perform a series of string operations. Pattern.compi

Free open source tool: Shorten the macOS menu bar and hide less commonly used content Free open source tool: Shorten the macOS menu bar and hide less commonly used content Dec 01, 2023 pm 02:38 PM

For macOS users, some commonly used software may be directly accessible through the Menubar in the upper right corner. However, as time goes by, you will find that there are more and more icons and your Menubar will gradually become longer and longer. If you use a MacBook, it is more likely to go beyond the middle position of the "bangs". This time I recommend a set of free and open source macOS tools called HiddenBar. Its biggest function is to allow you to shorten the Menubar and hide things that are not commonly used. Separated display area After installing this app, a separated area map will appear. Things on the left side of this mark will be hidden, and only things on the right side will be visible. Usage method 1: Set the partition first, and then move the less frequently used apps to the left of the partition. 2

ColorOS15 interface exposed. About this machine, here is a big change ColorOS15 interface exposed. About this machine, here is a big change Aug 28, 2024 pm 03:31 PM

Recently, ColorOS15 took the lead in launching internal beta testing. Some netizens exposed the relevant interface. Let’s see how it goes. As you can see in the picture above, some netizens posted the “About This Machine” interface of OPPO Find X7 after upgrading ColorOS15Beta. In addition to the big change in the top pattern, The configuration information in the lower half has also changed from the previous two columns to a single column vertical distribution. Attached is the "About This Phone/Mobile Phone" interface in the latest versions of mobile phones from six brands: Huawei, Honor, Xiaomi, OPPO, vivo, and Meizu. You can tell me which layout you like better. Regarding ColorOS 15, previous news said In addition to supporting LivePhoto live photos on a wide scale, it will also "support AirDrop&

PatternSyntaxException class in Java regular expressions PatternSyntaxException class in Java regular expressions Sep 11, 2023 pm 07:37 PM

The PatternSyntaxException class represents an unchecked exception thrown when a syntax error occurs in a regular expression string. This class contains three main methods namely - getDescription() - returns the description of the error. getIndex() - Returns the error index. getPattern() - Returns the regular expression pattern in which the error occurred. getMessage() - Returns the complete message containing the error, the index, the regular expression pattern in which the error occurred, and the error in the indicated pattern. Example Real-time demonstration importjava.util.Scanner;importjava.util.regex.Matcher;i

ColorOS15 interface exposed. About this machine, here is a big change ColorOS15 interface exposed. About this machine, here is a big change Aug 28, 2024 pm 03:31 PM

Recently, ColorOS15 took the lead in launching internal beta testing. Some netizens exposed the relevant interface. Let’s see how it goes. As you can see in the picture above, some netizens posted the “About This Machine” interface of OPPO Find X7 after upgrading ColorOS15Beta. In addition to the big change in the top pattern, The configuration information in the lower half has also changed from the previous two columns to a single column vertical distribution. Attached is the "About This Phone/Mobile Phone" interface in the latest versions of mobile phones from six brands: Huawei, Honor, Xiaomi, OPPO, vivo, and Meizu. You can tell me which layout you like better. Regarding ColorOS 15, previous news said In addition to supporting LivePhoto live photos on a wide scale, it will also "support AirDrop&

MacBook Pro Touch Bar could be resurrected as an Apple Pencil-enabled strip MacBook Pro Touch Bar could be resurrected as an Apple Pencil-enabled strip Apr 14, 2023 pm 09:19 PM

Apple has been working on how to make the iPad-centric Apple Pencil do the job of the old TouchBar on future MacBook Pro surfaces. This is just a patent, and Apple gets thousands of them every year, and it doesn't mean any actual product will ever appear. However, sometimes you have to wonder what the idea was, like now that patent drawings show a MacBook Pro with an Apple Pencil holder. That's a Mac that can hold an Apple Pencil. But you can't use Apple Pencil with a Mac, or not yet. Unless Apple is considering a very

See all articles