1 / 8

CIS*2450(S04) - Seminar 4

CIS*2450(S04) - Seminar 4. Trouble spots from A1 Practice with Regexs POSIX Regex Library Help on Assignment #2 Python Examples. Trouble Spots from A1. 1) Free'ing stuff that you did not malloc This is dangerous! Be careful to follow assignment specifications

benoit
Download Presentation

CIS*2450(S04) - Seminar 4

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CIS*2450(S04) - Seminar 4 Trouble spots from A1 Practice with Regexs POSIX Regex Library Help on Assignment #2 Python Examples

  2. Trouble Spots from A1 • 1) Free'ing stuff that you did not malloc • This is dangerous! • Be careful to follow assignment specifications • FILE * get cleaned up with fclose • 2) Spelling of findSubfield • Can submit compatibility regrade request w/reduced penalty • 3) Submitting correctly • tar czvf filename.tgz * • Submit same filename if submitting more than once

  3. Practice with Regular Expressions • '[.](mpe?g | avi | mp[23])$' • Lines ending with .mpg, .mpeg, .avi, .mp2, .mp3 • find ~ |egrep '[.](mpe?g|avi|mp[23])$' • '^[A-Z].*[A-Z]$' • Lines beginning and ending with a capital • '^.+printf.+[(].*[){]$' • Should match first line of all 'printf' functions • Anything wrong with this regexp?

  4. More Practice with Regular Expressions • Find all e-mails from the winter • Look for lines beginning with Date: <month> • Find all the one-line block comments in a C file • Match an unsigned byte value • Unsigned byte is [0,256) '^Date: (Jan|jan|January|january|…)' '/\*.*\*/' '^(([0-9])|([0-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5]))$'

  5. POSIX Regex Library (regex.h) • Three steps • 1) Compile Regex • regex_t structure • int regcomp(regex_t *compiled, const char *pattern, int cflags) • 2) Use Regex • int regexec(regex_t *compiled, char *string, size_t nmatch, regmatch_t matchptr [], int eflags) • 3) Clean-up Regex • void regfree(regex_t *compiled) • Cleans up the memory used internally by the struct but NOT the struct itself

  6. POSIX Regex - Example const char *expr=argv[1]; regex_t r; int temp; temp=regcomp(&r,expr,REG_NOSUB|REG_EXTENDED); if(temp) { printf("regcomp returned non-zero. Unable to compile regex\n"); return 1; } temp=regexec(&r,argv[2],0,NULL,0); if(!temp) { printf("regex (%s) matched string (%s)\n\n",argv[1],argv[2]); } else { printf("regex (%s) DID NOT match string (%s)\n\n",argv[1],argv[2]); } regfree(&r);

  7. Assignment #2 • Questions? • Comments? • Reminder: due on Feb 14 • Hand in structure chart: Feb 16 • Nicely printed (PPT, OpenOffice) is fine, *neatly* hand drawn is OK too. • Must match your "as built" code.

  8. Python Some Basic Examples

More Related