To find all the IMG tags, there is no label with the description attribute alt:
Regular: ]*?alt[^<>]*?>) .*?>
Example:
Extension, if you are looking for a with no title attribute, a should be:
Regular: <a (?!) [^<>]*?title[^<>]*?>) .*?>
Example: <a src= "alt=" "> <a src=" "> <a src=" "title=" "> <a src=" "id=" "> <a src=" "Title=" "Al T= "" >
use regular expressions to find words that do not contain the continuous string ABC
[^ABC] does not contain any characters in a, B, C, I want to implement an expression without a string ABC
As far as I am concerned, the simplest solution to this problem is to use the programming language to find out what is left of ABC, which is not included--the style of lazy people. But I write a tutorial, the reader may not have all the basics of programming, some just use some tools to extract some information from the TXT document, so to answer or must complete through the regular expression.
Then opened the Regextester, began to experiment, first tried to use (? Test ' abc ' |.) *(? (test) (?!)) (meaning: Look for ABC, or any character, if ABC is found, it is stored in the group named Test, to the final check whether there is content in the test group, if there is a failure to match, the relevant instructions see tutorial), the result is "abc", "Aabc", "ABCD", "AA" Can pass the test, it seems that the solution is not feasible until the test group exists and then backtrack.
Then try again (.) ABC) * (Find all characters that are not followed by ABC), the result is "abc", "ABCD" passed the test, "AABC" only intercepts the back "ABC", obviously not.
That strengthens the condition to try: ((? <!abc). (?! ABC) * (Find all previous and trailing characters that are not ABC), and the result is that all strings containing ABC only intercept the "ABC" Inside, and the ABC is passed directly.
It's a bit of a show now, but how do you filter out strings that contain ABC inside? The question, in other words, is how to match the whole, not the part? Now you need to be clear about the needs of the user: If the user wants to find a word, then add \b at both ends of the expression, plus ^ and $ if you are looking for a row. As the user's problem is not clearly stated, I think it is a word.
So wait for the expression: \b (? <!abc). ABC) *\b, after testing, this expression can match all words that do not contain ABC, and the word ABC.
How to exclude the word ABC? After some thinking, finally I think it is most convenient to judge whether a word begins with a: \b (A (?!). BC) | [^a] (?! ABC)) ((? <!abc). (?!) ABC)) *\b (either at the beginning of a not followed by a BC, or not with a, except that all characters must be preceded and followed by not ABC). After testing, fully meet the requirements, bingo!
Use regular expressions to find words that do not contain the continuous string ABC, and the final result: \b (A (?!) BC) | [^a] (?! ABC)) ((? <!abc). (?!) ABC)) *\b
----------------
Update: According to Maple's comments, the more concise approach is: \b (?! ABC) +\b \w)
Regular expression-does not contain a string
In situations where regular expressions are used, there is often a need to match a substring that does not contain a substring. For example, I'm going to get the substring before "CD" from "Eabcdfgh". Some people may write:
([^cd]*)
This writing is completely wrong, because [] is a collection, that is, [^CD] means not equal to C or D, not a CD. There are no CDs in the following program, but EAB is still being matched.
Copy Code code as follows:
String s = "([^cd]*)";
Match m = Regex.match ("Eabcfgh", s);
MessageBox.Show (m.value);//eab
MessageBox.Show (M.groups[1]. Value);//eab
The above writing is wrong more outrageous, normal youth can generally avoid this mistake. In special cases, regular expressions can be written in this way, and the efficiency is relatively high.
([/S/S]*CD)
First, the next/s/s is to indicate that any character matches. The special case is that I know there must be a CD in this string. If my requirement is to match a part that does not contain a CD (for the sake of convenience, match only the part before the CD), that is to say, the entire string should be taken out when the CD does not exist.
Copy Code code as follows:
String s = "((. (?!) CD)) ";
String s = "([/s/s]*cd)";
Match m = Regex.match ("Eabcdfgh", s);
MessageBox.Show (m.value);//eab
MessageBox.Show (M.groups[1]. Value);//eab
This writing finally meets the requirements. However, it is worth mentioning that, compared to the former, it is less efficient.
Review the relevant syntax:
(?: subexpression) defines a non-capturing group.
Copy Code code as follows:
Define a non-capture group
String s = "E (?: AB) (. *)";
Match m = Regex.match ("EABCD", s);
MessageBox.Show (m.value);//EABCD
MessageBox.Show (M.groups[1]. Value);//CD
AB is matched, but its group is not captured, Group[1] is a CD
(? = subexpression) 0-width positive lookahead assertion.
Copy Code code as follows:
0 width Positive lookahead assertion
String s = "B (cd|de) (. *)";
String s = "b (? =cd|de) (. *)";
Match m = Regex.match ("EABCDFG", s);
MessageBox.Show (M.value);
MessageBox.Show (M.groups[1]. Value);//Difference CD CDFG
There is a difference between the writing and the annotation, and the difference is "0 width", which is captured, that is, not a group.
(?! subexpression 0-width negative predictive lookahead assertion.
! The expression is not, is not contained, is also 0 width, will not be caught.
(? <= subexpression) 0 width is reviewed and then the assertion is made.
Example: (? <=19) \d{2}\b
"2003", "99" and "50" in "1851 1999 1950 1905 05"
(? <! subexpression) 0 width Negative review is followed by an assertion.
Example: (? <!19) \d{2}\b
"2003" and "51" in "1851 1999 1950 1905 03"