+ All Categories
Home > Documents > Computer Programming 2

Computer Programming 2

Date post: 05-Jan-2016
Category:
Upload: oleg
View: 45 times
Download: 3 times
Share this document with a friend
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 Presentation
Popular Tags:
12
Computer Programming 2 Lecture 7: String Processing Part d: Regular Expressions Prepared & Presented by: Mahmoud Rafeek Alfarra MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY (CST) KHANYOUNIS- PALESTINE
Transcript
Page 1: Computer Programming 2

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

Page 2: Computer Programming 2

و من يتِق� الله ...

قال ابن مسعود رضي الله عنه في قوله تعالى :

ات�ه� و ال ِق# ت"َق وا الل#ه َح )) ات#َق"( 102)آل عُمران :ت ُم"وت"ن# ((

قال : أن يطاع فال يعصي ويذكر فال ينسى وأن يشكر فال يكفر.

Mahmoud Rafeek Alfarra

2

Downloaded from http://staff.cst.ps/mfarraDownloaded from http://staff.cst.ps/mfarra

شريحـة ثابتـة لعلنا نحسن من خاللها أخالقنـا و أفعالنا لنفوز يوم االمتحان الحَقيَقي

Page 3: Computer Programming 2

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

Page 4: Computer Programming 2

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.

Page 5: Computer Programming 2

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.

Page 6: Computer Programming 2

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.

Page 7: Computer Programming 2

Regular expressions: QuantifiersRegular expressions: Quantifiers

Mahmoud Rafeek AlfarraDownloaded from Downloaded from http://staff.cst.ps/mfarra

7

Page 8: Computer Programming 2

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

Page 9: Computer Programming 2

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 …

Page 10: Computer Programming 2

Validating Example: SnapshotValidating Example: Snapshot

Mahmoud Rafeek AlfarraDownloaded from Downloaded from http://staff.cst.ps/mfarra

10

Page 11: Computer Programming 2

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

Page 12: Computer Programming 2

Next LectureNext Lecture… …

Mahmoud Rafeek AlfarraDownloaded from Downloaded from http://staff.cst.ps/mfarra

12

Introduction to

OOP

How to develop by?


Recommended