Presentation is loading. Please wait.

Presentation is loading. Please wait.

MORE APPLICATIONS OF REGULAR EXPRESSION By Venkata Sai Pundamalli id:

Similar presentations


Presentation on theme: "MORE APPLICATIONS OF REGULAR EXPRESSION By Venkata Sai Pundamalli id:"— Presentation transcript:

1 MORE APPLICATIONS OF REGULAR EXPRESSION By Venkata Sai Pundamalli E-mail id: vpundama@kent.edu

2 CONTENTS  Introduction to Regular Expression  Regular Expressions used in  Applications of Regular Expression a.RE in PHP b.RE in Databases c.RE in Voice Recognition

3 Regular Expression A regular expression is an algebraic formula whose value is a pattern consisting of a set of strings. Example: The set of strings over {A-Z,a-z} that contain the word “main” = A | B | ……. | Z | a | b | ……. | z * main * Here, * may or may not contain any combination of strings over {A- Z,a-z} * = { ε, a, b, aa, bb, ab, bc, ez, abc, main, part, …. }

4 Regular Expressions used in APPLICATIONSLANGUAGES Apache HTTP Server.NET Microsoft Visual StudioC++ NetbeansD Notepad++Java LibreOffice CalcJavaScript Oracle DatabasePerl PythonPHP Sublime TextRuby

5 a. Regular Expression in PHP  The ereg() function searches a string to match the given pattern, returning true if the pattern is found, and false otherwise. The search is case sensitive  The eregi() function searches a string to match the given pattern, returning true if the pattern is found, and false otherwise. The search is not case sensitive. Applications of Regular Expression

6 Difference between ereg and eregi: <?php $string = 'XYZ'; if (ereg('z', $string)) { echo "'$string' contains a 'z'"; } else { echo "'$string' contains a 'Z'!"; } ?> OUTPUT 'XYZ' contains a 'Z'! <?php $string = 'XYZ'; if (eregi('z', $string)) { echo "'$string' contains a 'z‘ or ‘Z’"; } else { echo "'$string' contains a 'Z'!"; } ?> OUTPUT 'XYZ' contains a ‘z‘ or ‘Z’!

7 <?php $string = "abcd"; $string1 = ereg("^a",$string); if($string1==1) echo "TRUE"; else echo "FALSE"; ?> <?php $string = "abcd"; $string1 = ereg("bc$",$string); if($string1==1) echo "TRUE"; else echo "FALSE"; ?> Output: TRUE Output: FALSE Examples of ereg in PHP:

8 <?php $string = "this is sample \nwhich is also sample"; echo $string; echo "\nAfter Replacement ::\n"; $string = ereg_replace("\n", "", $string); echo $string; ?> Output: this is sample which is also sample After Replacement :: this is sample which is also sample <?php $string = "this is sample"; $string = ereg_replace("^", " ", $string); echo $string; ?> Output: this is sample Contd.,

9 b. Regular Expression in Databases Oracle Database implementation of Regular Expressions SQL ElementDescription REGEXP_LIKEIt’s a condition used to match the given pattern REGEXP_COUNTIt’s a function which returns number of times the given pattern appears in the given string REGEXP_REPLACEIt’s a function which searches for a pattern in a character column and replace each occurrence of that pattern with the specified string

10 For instance, To ensure that phone numbers are entered into the database in a standard format. (XXX) XXX-XXXX DROP TABLE contacts; CREATE TABLE contacts ( l_name VARCHAR2(30), p_number VARCHAR2(30) CONSTRAINT c_contacts_pnf CHECK ( REGEXP_LIKE (p_number, '^\(\d{3}\) \d{3}-\d{4}$')) ); INSERT INTO contacts (p_number) VALUES('(650) 555-0100');

11 The following example examines the given string. Oracle returns the number of times that the word ‘the’ appears in the sting. SELECT REGEXP_COUNT ('The example shows how to use the REGEXP_COUNT function.', 'the', 1, 'i') ”REGEXP_COUNT” FROM dual; REGEXP_COUNT --------------------------------------- 2

12 The following example examines country_name. Oracle puts a space after each non-null character in the string. SELECT REGEXP_REPLACE (country_name, '(.)', '\1 ') "REGEXP_REPLACE" FROM countries; REGEXP_REPLACE ------------------------------------------------ A r g e n t i n a A u s t r a l i a B e l g i u m B r a z i l C a n a d a

13 For each name in the table whose format is "first middle last", we reposition the characters so that the format becomes "last, first middle": SELECT names "names", REGEXP_REPLACE (names, '^(\S+)\s(\S+)\s(\S+)$', '\3, \1 \2') AS "names after regexp" FROM famous_people ORDER BY "names"; names names after regexp --------------------------- --------------------------------- Harry S. Truman Truman, Harry S. John Quincy Adams Adams, John Quincy John Adams John Quincy Adams John Quincy Adams John_Quincy_Adams

14 c. Regular Expression in voice recognition  A Speech recognition application is capable of launching external applications based on the command we tell to it.  Regular Expression used in this application is: string command = Regex.Replace(line, "Start", "").Trim();  This application is written in C# with the help of Visual Studio Express.

15

16

17

18 References:  https://www.cs.rochester.edu/~nelson/courses/csc_173/fa/re.html  http://www.tutorialspoint.com/php/php_ereg.htm  http://docs.oracle.com/cd/E11882_01/appdev.112/e41502/adfns_regexp.htm #ADFNS00402  http://docs.oracle.com/cd/B28359_01/appdev.111/b28424/adfns_regexp.htm #CHDJAGEF  http://docs.oracle.com/cd/B12037_01/server.101/b10759/functions115.htm  http://www.prodigyproductionsllc.com/articles/programming/simple-speech- recognition-using-c-part-2/

19 Thank You Any Queries???


Download ppt "MORE APPLICATIONS OF REGULAR EXPRESSION By Venkata Sai Pundamalli id:"

Similar presentations


Ads by Google