הלינקייה: מגזין חודשי למפתחים

רוצה לשמוע על כל האירועים, המדריכים, הקורסים והמאמרים שנכתבו החודש ?
הלינקייה הינו מגזין חופשי בעברית שמשאיר אותך בעניינים.
בלי ספאם. בלי שטויות. פעם בחודש אצלך בתיבה.

Regular Expressions Exercise

Part 1

Write a program that prints only input lines that match the template:

  1. Write a regular expression to accept any binary string (only 0s and 1s)
  2. A binary string represents an even number if it ends with a 0. Write a regular expression to match an even number represented as a binary string.
  3. All lines from ls -l which represent a folder
  4. Lines longer than 50 characters
  5. Lines that have even length

Part 2

Write a program that takes a file with UNIX path names and translate it into windows paths (changing the / to \, and adding drive letter).
Sameple Input:

/etc/passwd
/home/bob/bookmarks.xml
/home/bob/vimrc

Sample output:

C:\etc\passwd
C:\home\bob\bookmarks.xml
C:\home\bob\vimrc

Part 3

Write a perl program that takes a CSV file with 3 fields: first name, last name, email; and swaps the columns, printing the values: last name, first name, email.
A sample input:

Shana,Sargent,shanasargent@isoswitch.com
Witt,Hampton,witthampton@zaphire.com
Morgan,Grant,morgangrant@lotron.com

And the output:

Sargent,Shana,shanasargent@isoswitch.com
Hampton,Witt,witthampton@zaphire.com
Grant,Morgan,morgangrant@lotron.com

Link To Solutions

Part 2

  1. Write a program to print every other word in a sentence. So for the input "I Love Writing Perl Code", it should print "I Writing Code"
  2. Write a program that takes lines of inputs and prints "Valid" if the line holds a legal perl variable identifier.
  3. Write a program to read a file and print lines containing only numbers
  4. Write a program that extracts words inside a double quoted strings. For instance, taking the input: he said "Goog Morning" and then went away, should produce the output: Good Morning
  5. Write a program that matches a time-of-day string (such as 9:14 am or 11:20 pm).
  6. Write a Regular expression to delete duplicate words
  7. Write a regular expression to match a valid email address.
  8. Write a regular expression to match a valid IP Address (remember that 0.0.0.0 is valid, but 300.0.0.0 is not)
  9. Write a regular expression that takes a line and prints only the words that have an odd number of letters
  10. Write a program that reads all file names in a directory and prints only the really long ones (longer than 20 characters)
  11. Write a program that reads all file names in a directory, and searches for secrets. If a file's extension is .txt, it should read it and print any line in ithe file with the words TOP SECRET somewhere on the line
  12. Write a program that calculates frequency of appearnce for words in text. The program should take a file name from the command line, and, for each word in the file, prints how many times it appears in the text.