4

Since only the first 3 characters for the English-language mnemonic matter, I prefer to reduce the words to just the first 3 letters only, for cold storage purposes. I would like to do this with a regular expression, to avoid manual errors.

What would be the shortest regular expression to do this? Note that I want a newline at the end. I will post my current solution, looking forward to see a shorter one.

dpzz
  • 4,539
  • 4
  • 22
  • 46

2 Answers2

4

You can simply use (\w{3})\w* (example) or (?:^| )(\w{3}) (example), whatever you prefer. There are a lot of other solutions possible as well.

You didn't provide a language, hence my solution to generic regex outside of language implementations should be advantageous.

James Cameron
  • 733
  • 4
  • 14
3

What I currently have:

echo $(echo "${MNEMONIC}" | tr " " "\n" | sed 's/^\(...\).*$/\1/' | tr "\n" " ")

dpzz
  • 4,539
  • 4
  • 22
  • 46