RosettaCodeData/Task/Semordnilap/Ed/semordnilap.ed
2024-10-16 18:07:41 -07:00

37 lines
1.8 KiB
Text

# by Artyom Bologov
H
# Remove words longer than 9 chars (unsupported)
g/^.\{9,\}$/d
# Join words insterspersed with |
g/./s/$/|/
,j
# Put exclamations before the semordnilaps words
g/./s/|\([^|]\)\([^|]\)\(|.*|\)\2\1|/|!\1\2\3/g
g/./s/|\([^|]\)\([^|]\)\(|.*|\)\2\1|/|!\1\2\3/g
g/./s/|\([^|]\)\([^|]\)\(|.*|\)\2\1|/|!\1\2\3/g
g/./s/|\([^|]\)\([^|]\)\(|.*|\)\2\1|/|!\1\2\3/g
g/./s/|\([^|]\)\([^|]\)\([^|]\)\(|.*|\)\3\2\1|/|!\1\2\3\4/g
g/./s/|\([^|]\)\([^|]\)\([^|]\)\(|.*|\)\3\2\1|/|!\1\2\3\4/g
g/./s/|\([^|]\)\([^|]\)\([^|]\)\(|.*|\)\3\2\1|/|!\1\2\3\4/g
g/./s/|\([^|]\)\([^|]\)\([^|]\)\(|.*|\)\3\2\1|/|!\1\2\3\4/g
g/./s/|\([^|]\)\([^|]\)\([^|]\)\([^|]\)\(|.*|\)\4\3\2\1|/|!\1\2\3\4\5/g
g/./s/|\([^|]\)\([^|]\)\([^|]\)\([^|]\)\(|.*|\)\4\3\2\1|/|!\1\2\3\4\5/g
g/./s/|\([^|]\)\([^|]\)\([^|]\)\([^|]\)\(|.*|\)\4\3\2\1|/|!\1\2\3\4\5/g
g/./s/|\([^|]\)\([^|]\)\([^|]\)\([^|]\)\(|.*|\)\4\3\2\1|/|!\1\2\3\4\5/g
g/./s/|\([^|]\)\([^|]\)\([^|]\)\([^|]\)\([^|]\)\(|.*|\)\5\4\3\2\1|/|!\1\2\3\4\5\6/g
g/./s/|\([^|]\)\([^|]\)\([^|]\)\([^|]\)\([^|]\)\(|.*|\)\5\4\3\2\1|/|!\1\2\3\4\5\6/g
g/./s/|\([^|]\)\([^|]\)\([^|]\)\([^|]\)\([^|]\)\(|.*|\)\5\4\3\2\1|/|!\1\2\3\4\5\6/g
g/./s/|\([^|]\)\([^|]\)\([^|]\)\([^|]\)\([^|]\)\([^|]\)\(|.*|\)\6\5\4\3\2\1|/|!\1\2\3\4\5\6\7/g
g/./s/|\([^|]\)\([^|]\)\([^|]\)\([^|]\)\([^|]\)\([^|]\)\(|.*|\)\6\5\4\3\2\1|/|!\1\2\3\4\5\6\7/g
g/./s/|\([^|]\)\([^|]\)\([^|]\)\([^|]\)\([^|]\)\([^|]\)\([^|]\)\(|.*|\)\7\6\5\4\3\2\1|/|!\1\2\3\4\5\6\7\8/g
g/./s/|\([^|]\)\([^|]\)\([^|]\)\([^|]\)\([^|]\)\([^|]\)\([^|]\)\(|.*|\)\7\6\5\4\3\2\1|/|!\1\2\3\4\5\6\7\8/g
g/./s/|\([^|]\)\([^|]\)\([^|]\)\([^|]\)\([^|]\)\([^|]\)\([^|]\)\([^|]\)\(|.*|\)\8\7\6\5\4\3\2\1|/|!\1\2\3\4\5\6\7\8\9/g
# Split on exclamation
g/./s/!/\
/g
# Remove the first (non-exclamated) line
1d
# Remove the rest of the line after semordnilap
g/|/s/\([^|]*\)|.*/\1/
,p
Q