120 likes | 276 Views
MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY (CST) KHANYOUNIS- PALESTINE. Computer Programming 2. Lecture 7: String Processing Part d: Regular Expressions. Prepared & Presented by: Mahmoud Rafeek Alfarra. و من يتقِ الله.
E N D
MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY (CST) KHANYOUNIS- PALESTINE Computer Programming 2 Lecture 7: String Processing Part d: Regular Expressions Prepared & Presented by: Mahmoud Rafeek Alfarra
و من يتقِ الله ... قال ابن مسعود رضي الله عنه في قوله تعالى : (( اتَّقُوا اللَّهَ حَقَّ تُقَاتِهِ وَلا تَمُوتُنَّ )) (آل عمران :102) قال : أن يطاع فلا يعصي ويذكر فلا ينسى وأن يشكر فلا يكفر. شريحـة ثابتـة لعلنا نحسن من خلالها أخلاقنـا و أفعالنا لنفوز يوم الامتحان الحقيقي Downloaded from http://staff.cst.ps/mfarra
Out Lines • Regular Expressions ,What and why ? • Introduction • Constructors • Count Tokens • Print Tokens • Token Processing Downloaded from http://staff.cst.ps/mfarra
What is Regular expressions? • Regular expressions are sequences of characters and symbols that define a set of strings. • They are useful for validating input and ensuring that data is in a particular format. Downloaded from http://staff.cst.ps/mfarra
Regular expressions Application • A large and complex regular expression is used to validate the syntax of a program. • If the program code does not match the regular expression, the compiler knows that there is a syntax error within the code. Downloaded from http://staff.cst.ps/mfarra
Regular expressions: Special symbols • A regular expression consists of literal characters and special symbols. Downloaded from http://staff.cst.ps/mfarra
Regular expressions: Quantifiers Downloaded from http://staff.cst.ps/mfarra
Regular expressions: Examples • [A-Z][a-z]+matches Ahmad, Zain • \\d{5} matches the Zip address as 12345, 34562,… • [1-9]\\d{2}-[1-9]\\d{2}-\\d{4} as 132 – 354 -6759 • [059][5|7|8|9]\\d{6} as 0597457687, 0595654532 Downloaded from http://staff.cst.ps/mfarra
Regular expressions: Validating Example • Write a program to receive the information of an student, and then print them, Taking into account the: • First and Last name must start with capital letter. • Mobile number must be started with 059, and the 4’th digit must be one of (5,7,8, 9) numbers, and the tottal number of digits is 10 digits. • The Id of male must start with 1 and of female with 2 • Other constraints … Downloaded from http://staff.cst.ps/mfarra
Validating Example: Snapshot Downloaded from http://staff.cst.ps/mfarra
More More about RegExp Chapter 29 in the textbook And http://staff.cst.ps/mfarra Downloaded from http://staff.cst.ps/mfarra
Next Lecture … Introduction to OOP How to develop by? Downloaded from http://staff.cst.ps/mfarra