In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces the example analysis that does not contain the specified string content after the regular expression, the article introduces in great detail, has certain reference value, the interested friends must read it!
In the past, it only knew / / .exec ("\ n"), which matched to this simple fixed writing, but the actual number of uses was close to zero.
Many scenes can not be written dead abc, it makes sense to write / / .exec ("\ n"), huh? How to match the previous one! From getting started to giving up.
Yesterday (2019-04-07) casually wrote / / .exec ("\ n"), it turned out to be right. + (?! Excluded string) the role of this structure can be misunderstood, no wonder it does not live up to expectations, (. (?! Excluded string) + is the positive solution.
Leaving an unsolved question, the one excluded after each character works well, and after a bunch of characters of undetermined length, why can't it work? won't foresight work with the previous +, *, {}? Explain. Look at the ending.
Attached: / / .exec ("\ n") can also be written. It may be at the end of the. + that doesn't match, but it still doesn't work like this: / / .exec ("\ n").
The regular expression matches the specified content with or without the specified string content:
To: it's relatively simple. Just write down what you want.
Don't: it's much more complicated than it is. How to eliminate it?
Premise principle
1. The string with fixed content in the expression can not be written as much as possible, and can be simplified as much as possible (for example, the abc part written above cannot be written dead).
two。 Can use a small amount of forward-looking (forward-looking), backward-looking (reverse) basically do not learn, but also study those browser support, do not dare to use, too much to learn.
3.NoJS (Not Only JavaScript); not just js; in browsers, but js's regular / exp/ literal writing is so concise that you don't need functions, objects, or strings; no rebuttal is accepted.
Suppose the text to be matched
HtmlRaw= `class= "matchX 1" class= "matchX 2" class= "matchX 3" class= "matchX 4" class= "matchX 5" class= "matchX 6". ` / Note: * is not fixed content, but there will be no unescaped xml entities, matchX, excludeX// Note: class= "matchX 123456" plain text is only used to demonstrate interference and should not be used as a feature / / if the data is not sensitive to line breaks, it should be preferentially converted to non-line breaks. High probability can simplify regular logic htmlNoWrap=htmlRaw.replace (/ [\ r\ n] + / g, "). / / regular test code (/ [\ s\ S] * / .exec (htmlRaw) | | []) [0]
Do not match a single character
Match the div.matchX tag:
You can directly use [^ >] to limit the matchX to the HTML tag, which means that the text in the text does not appear at the end of the > character.
A single character is fairly simple:
/ / valid /] + matchX [^ >] + > / .exec (htmlRaw) [0]
If it is not limited to the tag, the match may be out of bounds, and sooner or later something will go wrong:
/ invalid / / .exec (htmlNoWrap) [0] / / .exec (htmlRaw) [0] / / A newline character is long and ugly
Other single character scenarios can be used flexibly.
Do not want a string match
Matches the first piece of div without excludeX text content in the first layer, which returns the div containing matchX 4
[^] the syntax can only exclude a single character. What if you don't want a string? If you want to write it as [^ abc], you will eliminate all the a, b, and c characters; there seems to be no simple way but to use foresight.
Use the (at the beginning of this article.?! The excluded string)) + structure can achieve the goal, and the core is (?: [^ >] (?! excludeX)) *:
/ / effective /] * > [^ [^ 123:\ d + greedy match to. So far > 12: found that 123.1 does not match (?!\. 1), back one bit > no expression, return 12 / (. +) (?!\. 1) / .exec ("123.141") the visual observation is as follows: > 123.141v. + greedy match to the end > 123.141: match (?!\ .1) > there is no expression. Return 123.141 / (. (?!\. 1)) + / .exec ("123.141") visually looks like this: > 1. Match to the new bit > 1123 is consistent with (?!\. 1) > 12. Match to the new bit > 12 VRO 123. Conforms to (?!\. 1) > 123 purl. Match to a new bit > 12: found that 123.1 does not match (?!\. 1), back one bit, and exit the loop > there is no expression, return 12
If you want to do a forward-looking check on each character, only the last way to write it is easier to understand.
The above is all the contents of the article "sample Analysis of regular expressions without specified string contents". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.