computer programming 2
DESCRIPTION
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. و من يتقِ الله. - PowerPoint PPT PresentationTRANSCRIPT
Computer Programming 2
Lecture 7:String Processing
Part d: Regular Expressions
Prepared & Presented by: Mahmoud Rafeek
Alfarra
MINISTRY OF EDUCATION & HIGHER EDUCATIONCOLLEGE OF SCIENCE AND TECHNOLOGY (CST)KHANYOUNIS- PALESTINE
و من يتِق� الله ...
قال ابن مسعود رضي الله عنه في قوله تعالى :
ات�ه� و ال ِق# ت"َق وا الل#ه َح )) ات#َق"( 102)آل عُمران :ت ُم"وت"ن# ((
قال : أن يطاع فال يعصي ويذكر فال ينسى وأن يشكر فال يكفر.
Mahmoud Rafeek Alfarra
2
Downloaded from http://staff.cst.ps/mfarraDownloaded from http://staff.cst.ps/mfarra
شريحـة ثابتـة لعلنا نحسن من خاللها أخالقنـا و أفعالنا لنفوز يوم االمتحان الحَقيَقي
Out Lines Out Lines
Mahmoud Rafeek AlfarraDownloaded from Downloaded from http://staff.cst.ps/mfarra
3
Regular Expressions ,What and why ?
Introduction Constructors Count Tokens Print Tokens Token Processing
What is Regular expressions?What is Regular expressions?
Mahmoud Rafeek AlfarraDownloaded from Downloaded from http://staff.cst.ps/mfarra
4
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.
Regular expressions ApplicationRegular expressions Application
Mahmoud Rafeek AlfarraDownloaded from Downloaded from http://staff.cst.ps/mfarra
5
• 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.
Regular expressions: Special symbolsRegular expressions: Special symbols
Mahmoud Rafeek AlfarraDownloaded from Downloaded from http://staff.cst.ps/mfarra
6
• A regular expression consists of literal characters and special symbols.
Regular expressions: QuantifiersRegular expressions: Quantifiers
Mahmoud Rafeek AlfarraDownloaded from Downloaded from http://staff.cst.ps/mfarra
7
Regular expressions: ExamplesRegular expressions: Examples
Mahmoud Rafeek AlfarraDownloaded from Downloaded from http://staff.cst.ps/mfarra
8
• [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
Regular expressions: Validating ExampleRegular expressions: Validating Example
Mahmoud Rafeek AlfarraDownloaded from Downloaded from http://staff.cst.ps/mfarra
9
• 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 …
Validating Example: SnapshotValidating Example: Snapshot
Mahmoud Rafeek AlfarraDownloaded from Downloaded from http://staff.cst.ps/mfarra
10
MoreMore
Mahmoud Rafeek AlfarraDownloaded from Downloaded from http://staff.cst.ps/mfarra
11
More about RegExp
Chapter 29 in the textbook
And
http://staff.cst.ps/mfarra
Next LectureNext Lecture… …
Mahmoud Rafeek AlfarraDownloaded from Downloaded from http://staff.cst.ps/mfarra
12
Introduction to
OOP
How to develop by?