Homework 3

Regular Expressions

1.

Prompt:
First String    Second      1.22      3.4
Second          More Text   1.555555  2.2220
Third           x           3         124
Input:
> Find: \h{2,}+
> Replace: ,
Output:
First String,Second,1.22,3.4
Second,More Text,1.555555,2.2220
Third,x,3,124

2.

Prompt:
Ballif, Bryan, University of Vermont
Ellison, Aaron, Harvard Forest
Record, Sydne, Bryn Mawr
Input:
> Find: (\w+)\, (\w+)\, (.*)
> Replace: \2 \1 \(\3\)
Output:
Bryan Ballif (University of Vermont)
Aaron Ellison (Harvard Forest)
Sydne Record (Bryn Mawr)

3.

Prompt:
0001 Georgia Horseshoe.mp3 0002 Billy In The Lowground.mp3 0003 Cherokee Shuffle.mp3 0004 Walking Cane.mp3
Input:
> Find: \s(\d{4})
> Replace: \r\1
Output:
0001 Georgia Horseshoe.mp3
0002 Billy In The Lowground.mp3
0003 Cherokee Shuffle.mp3
0004 Walking Cane.mp3

4.

Prompt:
0001 Georgia Horseshoe.mp3
0002 Billy In The Lowground.mp3
0003 Cherokee Shuffle.mp3
0004 Walking Cane.mp3
Input:
> Find: (\d{4})\s(.*)(.mp3)
> Replace: \2_\1\3
Prompt:
Georgia Horseshoe_0001.mp3
Billy In The Lowground_0002.mp3
Cherokee Shuffle_0003.mp3
Walking Cane_0004.mp3

5.

Prompt:
Camponotus,pennsylvanicus,10.2,44
Camponotus,herculeanus,10.5,3
Myrmica,punctiventris,12.2,4
Lasius,neoniger,3.3,55
Input:
> Find: (\w)\w+\,(\w+),\d+.\d+
> Replace: \1_\2
Output:
C_pennsylvanicus,44
C_herculeanus,3
M_punctiventris,4
L_neoniger,55

6.

Prompt:
Camponotus,pennsylvanicus,10.2,44
Camponotus,herculeanus,10.5,3
Myrmica,punctiventris,12.2,4
Lasius,neoniger,3.3,55
Input:
> Find: (\w)\w+\,(\w{4})\w+,\d+.\d+
> Replace: \1_\2
Output:
C_penn,44
C_herc,3
M_punc,4
L_neon,55

7.

Prompt:
C_pennsylvanicus,44
C_herculeanus,3
M_punctiventris,4
L_neoniger,55
Input:
> Find:(\w{3})\w+\,(\w{3})\w+\,(\d+\.\d+)(\,)(\d+)
> Replace: \1\2\4 \5\4 \3
Output:
Campen, 44, 10.2
Camher, 3, 10.5
Myrpun, 4, 12.2
Lasneo, 55, 3.3

Head back to the Homework Hub.