suhadma blog
Kamis, 31 Mei 2012
Mysql Regular Expressions Metacharacters
IntroductionThis is conception 2 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 the uses of metacharacters in MySQL Regular Expressions.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 || Claws | Gwen Jones | felid | m | 2004-03-17 | NULL || painter | Gwen | shuttle | NULL | 2007-12-09 | NULL |You should effort the SELECT statements presented beneath with this table.The ^ CharacterThe ^ case is utilised to correct the prototypal of the subject. The mass SELECT evidence module convey the prototypal and ordinal rows, matching âBuffyâ and âBowserâ in the prototypal and ordinal cells of the prototypal column: SELECT * from Pets where study rLike "^B";The ornament (regex) is "^B". In the subjects, âBuffyâ and âBowserâ, âBâ is at the beginning. Note the function of ^ (at the beginning) in the pattern.The $ CharacterThe $ case is utilised to correct the modify of the subject. The mass SELECT evidence module convey the prototypal and ordinal rows, matching âBuffyâ and âFluffyâ in the prototypal and ordinal cells of the prototypal column: SELECT * from Pets where study rLike "fy$";The ornament is "fy$". In the subjects, âBuffyâ and âFluffyâ, âfyâ is at the end. Note the function of $ (at the end) in the pattern.The . CharacterThe extend case is utilised to correct some case in the subject. It would also correct the posture convey or the newline character. The mass SELECT evidence module convey the ordinal and ordinal rows, matching âGwen Jonesâ and âGwenâ in the ordinal and ordinal cells of the ordinal column: SELECT * from Pets where someone rLike "Gw.n";The ornament is "Gw.n". In the subjects, âGwen Jonesâ and âGwenâ, âeâ corresponds to the extend in the pattern. So, some person that has Gwen or Gwan or Gwsn or Gwin, etc is matched. In these words, the extend corresponds to âeâ or âaâ or âsâ or âiâ respectively. The extend corresponds to some character, in a portion position, in a pattern.The subject, âGwen Jonesâ has been matching because the evidence looks for the word, "Gw.n" within the person that strength be a daylong string. Once the evidence sees the ornament within a person (string), no concern how daylong the person is, it matches it.The x* ConstructHere, âxâ is a uncertain (place holder) for some character. The * meet after âxâ means, correct some ordering (consecutive) of set or more âxâ characters. The pattern, "se*n" for example, would correct âseenâ; it would correct âsenâ; and it would correct âsnâ. That is, âe*â would correct set or more âeâ in sequence. The mass SELECT evidence module convey the prototypal and ordinal rows, matching âBuffyâ and âFluffyâ in the prototypal and ordinal cells of the prototypal column: SELECT * from Pets where study rLike ".*f*y";The ornament is ".*f*y" . In the subjects, âBuffyâ and âFluffyâ, â.*â corresponds to âBuâ and âFluâ in âBuffyâ and âFluffyâ respectively. â.*â effectuation correct some character, set or more times. Still in the subjects, âBuffyâ and âFluffyâ, âf*yâ corresponds to âffyâ in âBuffyâ and âFluffyâ. âf*â effectuation correct âfâ set or more times.The x+ ConstructHere, âxâ is a uncertain for some character. The + meet after âxâ effectuation correct some ordering (consecutive) of digit or more âxâ characters; as anti to * which matches set or more characters. The pattern, "se+n" , for example, would correct âseenâ; it would correct âsenâ; but it would not correct âsnâ, which does not hit at small digit âeâ. The mass SELECT evidence module convey the ordinal row, matching âbirdâ in the ordinal radiophone of the ordinal column: SELECT * from Pets where species rLike "b.+d";The ornament is "b.+d" . In the subject, âbirdâ, âirâ are some digit characters in ordering matching by â.+â. â.+â matches some case (not needs the aforementioned character) that occurs in ordering digit or more times. If you poverty a portion case in sequence, then identify the case in locate of the dot, as in âe+â against âseenâ.The x? ConstructHere, âxâ is a uncertain for some character. The ? meet after âxâ effectuation correct either set or digit âxâ character. The mass SELECT evidence module convey the third, ordinal and ordinal rows, matching âFluffyâ, âClawsâ, and âWhistlerâ in the third, ordinal and ordinal cells of the prototypal column: SELECT * from Pets where study rLike "l";The ornament is "l". Each of the subjects, âFluffyâ, âClawsâ, and âWhistlerâ has âlâ. So matching occurs. Remember, erst a ornament is institute in a subject, matching occurs. Now the mass SELECT evidence module superior every the fivesome rows of the table, matching the first, second, third, ordinal and ordinal cells of the prototypal column: SELECT * from Pets where species rLike "l?";The ornament is "l?". The subjects are, âBuffyâ, âBowserâ, âFluffyâ, âClawsâ and âWhistlerâ. Each of these subjects has set or digit âlâ; and so apiece is matching and so every fivesome rows are selected.The | CharacterThe | case effectuation OR. It effectuation correct either what is on the mitt of | or what is on the right. The mass SELECT evidence module superior the rows, whose radiophone in the ordinal article has either âHaroldâ or âDianeâ. SELECT * from Pets where someone rLike "Harold|Diane";The ornament is "Harold|Diane". Note that the evidence returns 3 rows. The threesome subjects are: âHaroldâ, âDianeâ and âHarold Taylorâ institute in the cells of the prototypal 3 rows, in the ordinal column. Each of the subjects has âHaroldâ or âDianeâ. The ordinal person has more book than meet âHaroldâ, but it ease has âHaroldâ or âDianeâ.The deciding book (characters) haw subsist exclusive in digit person or in assorted subjects. Let us countenance at added example. The mass SELECT evidence module superior the rows, whose radiophone of the ordinal article has either âGwenâ or âJonesâ. SELECT * from Pets where someone rLike "Gwen|Jones";The ornament is "Gwen|Jones". The ordinal and ordinal rows were selected. The subjects are, âGwen Jonesâ and âGwenâ. Note that âGwenâ is institute in either of the subjects and it is sufficiency for the digit subjects to be selected. âJonesâ is institute exclusive in âGwen Jonesâ and it is sufficiency for âGwen Jonesâ to be selected. If the ordinal bed did not exist, exclusive the ordinal bed with âGwen Jonesâ would hit been selected; that is, âGwenâ or âJonesâ would hit designated âGwen Jonesâ. So the | (OR) case effectuation either book crapper be chosen from the aforementioned person or assorted subjects.You hit seen MySQL lawful expressions metacharacters and ultimate ornament constructs in this conception of the program Let us kibosh here and move in the incoming conception with more ornament constructs.
may be useful for you
suhadma blog
suhadma blog
Langganan:
Posting Komentar (Atom)
0 komentar:
Posting Komentar