Pages

Kamis, 31 Mei 2012

Mysql Regular Expressions Pattern Constructs

please a readIntroductionThis is conception 3 of my series, MySQL Regular Expressions. I adopt you hit feature the preceding conception of the series. This is the continuation. In this conception of the program we countenance at MySQL Regular Expressions Pattern Constructs. In the preceding conception of the series, we saw a whatever ultimate ornament constructs. Here, we shall countenance at the more elaborated ornament constructs.Database plateau for IllustrationWe shall ingest the mass database plateau titled Pets, for illustration:| study   | someone  | species | stimulate  | relationship      | modification      |+--------+--------+---------+------+------------+------------+| Buffy  | Harold | canid     | f    | 1999-05-13 | NULL       || Bowser | Diane  | canid     | m    | 1999-08-31 | 2005-07-29 || Fluffy | Harold  Taylor | felid     | f    | 2003-02-04 | NULL  || Timtim    | Gwen  Jones | felid     | m    | 2004-03-17 | NULL       || painter | Gwin  | bir5d    | NULL | 2007-12-09 | NULL       |The accumulation in this plateau is slightly assorted from the member in the plateau of the preceding conception of the series. You should be investigating the SELECT statements presented beneath with this table.The (abc) ConstructHere, (abc) exclusive effectuation one, two, three, four, five, etc. characters in parentheses. In a pattern, parentheses assemble characters into a set. The ordered of characters in the ornament behaves as a azygos housing and the primary characters we saw in the preceding conception of the series, crapper be practical on them as if they were a azygos character. For example, you crapper hit something like, (ab)+, (abc)*, (abcd)?, etc. The mass SELECT evidence returns the ordinal bed of the above table, matched the ordinal radiophone value, “Timtim” of the prototypal column:    SELECT * from Pets where study rLike "(tim)+";The ornament is, "(tim)+" . The ornament matches member or more (tim) in member subject. The person matched is, “Timtim”; there are member (tim) in the subject. If the ornament were, “(tim)*” , every the radiophone values of the prototypal article would hit matched, because, * effectuation ordered or more (while + effectuation member or more).The [[:<:]], [[:>:]] ConstructsA articulate is a ordering of articulate characters that is not preceded by or followed by articulate characters. A articulate housing is an alphamerical housing or an underscore, _. Examples of articulate characters are: ‘a’, ‘b’, ‘c’, ‘1’, ‘2’, ‘3’, etc. the marker, [[:<:]] in a ornament matches the beginning of a word. The marker, [[:>:]] in a ornament matches the modify of a word. These constructs are word-boundary markers. They are not characters; they are bounds identifiers. The mass SELECT evidence returns the ordinal bed of the above table, matched “Gwen” in the subject, “Gwen  Jones” of the ordinal radiophone in the ordinal column:    SELECT * from Pets where someone rLike "Gwen[[:>:]]";The ornament is, "Gwen[[:>:]]" . It begins with the word, “Gwen” followed by the modify of articulate marker, [[:>:]] . So, it matches “Gwen” and its modify in the subject, “Gwen  Jones”. In the subject, after the word, “Gwen”, you hit a word-boundary before the expanse character. The [[:<:]] is utilised in a kindred way, but in face of the word.Note that apiece word-boundary symbolisation has member pairs of oppositeness conservativist brackets, member colons and a < or > character.The [a-dX] and [^a-dX] ConstructsThe extend primary housing matches whatever azygos character. What most the housing when you poverty to correct a azygos housing from a ordered of characters? Consider the words, “Gwen”, “Gwin”, “Gwan” and “Gw4n”. The text dissent in the housing at the ordinal position. The prototypal articulate has ‘e’ in the ordinal position; the ordinal articulate has ‘i’ in the ordinal position; the ordinal articulate has ‘a’ in the ordinal position; and the ordinal articulate has ‘4’ in the ordinal position. So you haw be fascinated to correct the characters, ‘e’, ‘i’, ‘a’ and ‘4’. This effectuation you poverty to correct member housing from the set, [eia4]. The ornament for this housing is, "[eia4]", which would correct a azygos housing at a function in a person that is, ‘e’ or ‘i’ or ‘a’ or ‘4’.The mass SELECT evidence module convey the ordinal and ordinal rows of the plateau above, matched “Gwen  Jones” in the ordinal radiophone and “Gwin” in the ordinal cell, every in the ordinal column.    SELECT * from Pets where someone rLike "Gw[eia4]n";The ornament in the evidence is, "Gw[eia4]n" . The subjects are “Gwen  Jones” and “Gwin”. The articulate participating in the subjects, is “Gwen” for “Gwen  Jones” and “Gwin” for “Gwin”. “Gwen” and “Gwin” dissent in the ordinal function of the characters. So, in the subject, “Gwen  Jones”, ‘e’ in “Gwen” is matched and in the subject, “Gwin”, ‘i’ is matched. ‘e’ and ‘i’ are in the ordinal function of the words, “Gwen” and “Gwin” respectively. In the pattern, "Gw[eia4]n" , [eia4] is in the ordinal position.Note: [eia4] and (eia4) stingy assorted things. [eia4] effectuation ‘e’ or ‘i’ or ‘a’ or ‘4’;  while (eia4) effectuation impact the ordered of characters, “eia4”, as a azygos character.Ranges[eia4] from above is an warning of a class. What most the case, where you poverty a correct from the class, [abcde] ? Note that this is a arrange of characters of the ABC from ‘a’ to ‘e’. [abcde] is meliorate cursive as, [a-e] . Note the ingest of the hyphen.You crapper consortium a arrange with azygos characters. For example, [a-dX] effectuation ‘a’ or ‘b’ or ‘c’ or ‘d’ or ‘X’ , that is, the arrange a-d and X.You crapper also hit a arrange with digits, e.g. [0-5], [3-9], [0-9]Negating the ClassIf you poverty to correct a housing at a function in the person eliminate the ones in the class, then you would ingest the ^ symbol. So, if you poverty to correct whatever housing eliminate the ones in [a-dX] , you would identify [^a-dX] in the pattern. Note the ingest and function of ^ in the collection construct. The mass SELECT evidence module convey the prototypal and ordinal rows, matching, “dog” in the prototypal and ordinal cells of the ordinal colon:    SELECT * from Pets where species rLike "d[^a-n]g";The ornament in the evidence is "d[^a-n]g" message that no housing in the range, a-n, should be matched at the function in question. The ornament matched, begins with ‘d’, followed by a housing that is not in the range, a-n, and then followed by ‘g’. ‘o’ is not in the range, so “dog” is matched.Formal Character ClassesSome classes are so essential that they hit names. The mass itemize gives the obloquy of these classes and their descriptions:Name: Descriptionalnum: Alphanumeric charactersalpha: Alphabetic charactersblank: Whitespace characterscntrl: Control charactersdigit: Digit charactersgraph: Graphic characterslower: Lowercase alphabetized charactersprint: Graphic or expanse characterspunct: Punctuation charactersspace: Space, tab, newline, and posture returnupper: Uppercase alphabetized charactersxdigit: Hexadecimal member charactersTo ingest whatever of these classes, you ingest the symbolisation construct, [[:name:]] .The mass SELECT evidence module convey the terminal bed in the plateau matched “bir5d” for the digit, 5, in the ordinal radiophone of the ordinal column:    SELECT * from Pets where species rLike "bir[[:digit:]]d";The ornament is, "bir[[:digit:]]d" . So the person “bir5d” , having the digit, 5, at the ordinal function is matched. [[:digit:]] is at the ordinal function of the pattern, "bir[[:digit:]]d".The x{m}, x{m, } and x{m,n} ConstructsLet m and n be integers (whole numbers). x{m} in a ornament matches just m serial instances of x. x{m, } matches at small m serial instances of x. x{m,n} matches between m and n serial instances of x. We today countenance at whatever examples.The pattern, "fe{1}d" , matches the person “fed”, where ‘e’ is matched just member time. The pattern, "fe{1,}d" , matches the subject, “fed” and the subject, “feed”, where ‘e’ is matched at small once. The pattern, "fe{1,2}d" , matches the subject, “fed” and the subject, “feed” , where ‘e’ is matched at small member instance and at most 2 times.The constructs are not exclusive utilised for a character; they crapper also be utilised for an corpuscle (piece of the pattern). So, the pattern, "a[bcd]{3}e" matches the subject, “abcde”. The pattern, "a[bcd]{3,}e" matches the subject, “abcde”. The pattern, "a[bcd]{1,10}e" matches the subject, “abcde”. The corpuscle is [bcd].Now, [bcd] effectuation ‘b’ or ‘c’ or ‘d’. So the change pattern, "[bcd]{3)" ,  means “bbb” or “ccc” or “ddd” or “bcb” or “cbc” or “dcd” or “bdb” or “cdc” or “dbd”.  The change ornament [bcd]{3,} effectuation a compounding of at small whatever of the threesome characters. The change pattern, [bcd]{1,10}, effectuation at small member housing from the threesome characters, up to a compounding of 10 characters from the 3 characters.White Space CharactersWhite expanse housing literals are: 'b', 't', 'n', 'v', 'f', and 'r'. The obloquy of these literals are respectively, backspace, tab, newline, vertical-tab, form-feed and carriage-return.You crapper ingest the whitespace housing literals, direct in the pattern. Assume that you had the mass bed additional to the table:| Lion | saint | finsh | f | 2008-12-09 | NULL |The radiophone for species has the value, “finsh”, with the newline character, ‘n’. The mass SELECT evidence module convey the row, matched the subject, “finsh”.    SELECT * from Pets where species rLike "finsh";The ornament is, "finsh".You crapper also ingest the study of the albescent expanse character, but in this case, you module hit to locate it in the marker, [[.name.]] . The mass SELECT evidence returns the additional row, matched the subject, "finsh".    SELECT * from Pets where species rLike "fi[[.newline.]]sh";The ornament is, "fi[[.newline.]]sh" .You crapper ingest the exact in the marker. The mass SELECT evidence returns the additional row, matched the subject, "finsh".    SELECT * from Pets where species rLike "fi[[.n.]]sh";The ornament is, "fi[[.n.]]sh"The symbolisation has member pairs of oppositeness conservativist brackets and member dots.The MySQL Regular Expressions MetacharactersA metacharacter is a housing utilised to curb or delimitate another characters. In the housing of patterns, the MySQL Regular Expressions metacharacters are:    ^ $  . * + ? | * { } [ ]  : = > <In visit to ingest whatever of these metacharacters in a pattern, you hit to antecede it with member backslashes. In this way, it module be seen as an mediocre housing and it module not hit its circumscribed effect. So, the pattern, "2\+3\=6" , module correct the subject, “2+3=5” .posted by
suhadma blog

0 komentar:

Posting Komentar