Pages

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

0 komentar:

Posting Komentar