#a regex is a DFA and so has finite state
Explore tagged Tumblr posts
Text
as an example of how sed is more than just regex: regex cannot find palindromes. a regex can only deal with finite information, but words can be arbitrarily long. it is mathematically impossible for a regex to find palindromes (of arbitrary length.)
but sed is more than just regex, so you can find palindromes like so:
sed -nE 'h ; :x ; /^.?$/{g;p;d} ; s/^(.)(.*)\1$/\2/ ; tx'
and if you want to remove whitespace and punctuation then just do
sed -nE 'h ; s/[^[:alnum:]]//g ; tx ; :x ; /^.?$/{g;p;d} ; s/^(.)(.*)\1$/\2/ ; tx'
sed 's/[rRlL]/w/g' is the same as sed 's/[rl]/w/gi'. but why not just do sed 'y/rlRL/wwWW/'?
#a regex is a DFA and so has finite state#if it has n states then just have a palindrome with >2n letters in it#and then yay! itll be fucked!#yippee!
7 notes
·
View notes