1
2
3
4
5
$ perl -wle ' $a = "a\nb"; print $1 while $a =~m/^(.)/g'
a
$ perl -wle ' $a = "a\nb"; print $1 while $a =~m/^(.)/gm'
a
b
/^(\d{4}),(-?\d+)$/
1
2
3
4
# zwei zeilen, eine mit linux, eine mit dos umbruch
# ausgabe mit print wenn der regex matchen konnte
$ echo -e "1234,5678\n2345,6789\r\n" | perl -nle 'print "$1 $2" if m/^(\d+),(\d+)$/;'
1234 5678
QuoteTo do this, we would use the anchor metacharacters ^ and $ . The anchor ^ means match at the beginning of the string and the anchor $ means match at the end of the string, or before a newline at the end of the string.
2009-07-18T10:34:25 GwenDragon