Understand regular expressions

xiaoxiao2021-03-17  198

Abstract I believe that everyone has heard of the regular arithmetic model, use it to perform high-speed search, replacement, and so on in the field. The text can be easily controlled using the regular operation. For example, if you want to know if a string is in "0.1" - "9.9" (note, only one deciple), what method will you use to do this? I think you will detect a char, this will be very troublesome, you need a lot of code. We have a simpler and faster solution here, that is, the regular operation. This article will reflect the application and composition of the regular operation by actual example. The purpose of this article is to throw bricks, from one example to find out the use of regular expressions, I hope the reader can be able to scrutinize their own, or discuss it. Further explore the use of regular expressions. Example detection strings are "0.1" - "9.9" answer: ^ [0-9] /. (? (? <= 0 /.) [1-9] | [0-9]) $ analysis: ^ - The beginning of a row or string. $ - the end of a row or String. [0-9] - any one from 0 to 9. /. - One".". (Expression) YES | NO) - This represents a selection (three-metron operator), if the expression is searched here, do the YES part, otherwise the NO portion is executed. Pay attention to no space! (? <= expression) - This is to say that there is Expression on the left of the current position. Ok, if we say that it means: "The first character is any number from 0 to 9, followed by one. Then, if the first two characters are 0., the last character is It is any number of 1 to 9, and if the first two characters are not 0., then the last character can be any number of 0 to 9.

转载请注明原文地址:https://www.9cbs.com/read-129610.html

New Post(0)