suhadma blog
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
suhadma blog
Langganan:
Posting Komentar (Atom)
0 komentar:
Posting Komentar