suhadma blog
Kamis, 31 Mei 2012
Overview of Mysql Regular Expressions
welcome in my blog IntroductionThis is conception 1 of my series, MySQL Regular Expressions. In this conception of the series, I inform you to the topic, MySQL Regular Expressions. Regular expressions care with text. The message module be explained as you feature this tutorial.PrerequisiteBefore achievement here, you requirement to hit awninged the series, whose prototypal parts hit the mass titles:- Database- Normalization- Referential Integrity in Database- Implementing Database in MySQLTo accomplish some of the series, meet identify the denomination and my study Chrys in the Search Box of this tender and utter Search.The SQL SELECT StatementConsider the mass database table:| 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 |Let the study of the plateau be, Pets. The prototypal article has the study of the pet and the ordinal has the study of the someone of the pet. This plateau has accumulation most pets and the grouping who possess them. The mass SELECT evidence would superior the prototypal and ordinal rows: SELECT * from Pets where species = "dog";Reason for Regular ExpressionsYou undergo how to superior rows, when the string, e.g. âdogâ above, matches the continuance of a article radiophone in the table. In the above superior statement, "dog" matches the prototypal and ordinal radiophone values in the ordinal article of the table. You undergo how to do this category of thing, already. What most the housing when you poverty the rows, where the study (cell value) of the species has a âdâ ? In the table, the species names with a âdâ are âdogâ and âbirdâ. The prototypal honor in âdogâ is âdâ and the terminal honor in âbirdâ is also âdâ. In another words, you poverty the first, ordinal and terminal rows. The mass superior evidence module superior these 3 rows, matching exclusive the character, âdâ in the ordinal column. SELECT * from Pets where species rLike ".*d.*";In this statement, ".*d.*" , without the quotes, is an warning of what is called, a pattern. It means, some progress that has the letter, âdâ. rLike means, like. So the evidence selects rows where species are aforementioned ".*d.*".PatternA ornament is a ordered of characters much as ".*d.*" , that determines what is matching in a string. In the above plateau and in the ordinal column, âdogâ and âbirdâ are matched. âdogâ is designated from the digit instances of âdogâ and âbirdâ is designated from the azygos happening of âbirdâ. There are fivesome choices to opt from, in the ordinal column. The choices are: âdogâ (twice), âcatâ (twice) and âbirdâ (once). Each of these choices is a string. Such a progress is called, a subject. Note: It is doable for you to hit a plateau of exclusive digit bed with meet digit subject. In the above housing there are 5 subjects. So in a lawful countenance situation, you hit the subject, the distant word, rLike, and the pattern. Note: rLike is an cause kindred to the naming operator, = .The ornament is prefabricated up of mediocre characters and Metacharacters. These characters are compounded in a primary artefact to modify an expression. So you crapper call a pattern, a lawful expression, or simply, regex.Single Word MatchingYou crapper hit a person prefabricated up of more than digit word, aforementioned in a sentence. Matching digit articulate in much a subject, is simple. In that case, the regex (pattern) is meet the articulate to correct (look for) aforementioned in the mass statement: SELECT * from Pets where someone rLike "Gwen";Here, the regex is, "Gwen", the azygos word. In the above table, there are digit subjects, which are, âGwen Jonesâ and âGwenâ from the terminal digit cells of the ordinal article of the table. In this case, âGwenâ module be identified in the terminal digit cells of the ordinal column, and so the superior evidence module convey the terminal digit rows of the table.NOT rLikeNow, NOT rLike , is the oppositeness cause to, rLike. Consider the mass SELECT statement: SELECT * from Pets where species NOT rLike ".*d.*";On the above table, this SELECT evidence module convey the ordinal and ordinal rows that do not hit âdâ in some of the section (cell values) in the ordinal column.Note: In the operator, rLike, the r stands for regex.Case Sensitivity for MatchingMatching in MySQL Regular Expressions is housing insensitive. So the pattern, ".*d.*" and ".*D.*" hit the aforementioned effect.Matching SpacesThe expanse housing crapper also be matched. You identify the expanse in the ornament as usual, using the spacebar key on the keyboard. The mass SELECT evidence returns the ordinal row: SELECT * from Pets where someone rLike "Gwen ";The ornament is, "Gwen " . It has a expanse after âGwenâ. In the table, the exclusive locate where âGwenâ followed by a expanse crapper be identified, is in the ordinal radiophone in the ordinal column. So the person matching is, âGwen Jonesâ and the ordinal bed is returned.
posted by
suhadma blog
suhadma blog
Langganan:
Posting Komentar (Atom)
0 komentar:
Posting Komentar