WordService Extension: Remove white space

Hey,

I just found out about WordService and wonder if there’s the possibility to add custom scripts, so that everything’s in one place, nice and tidy. I’m frequently encountering l e t t e r s p a c e d t e x t and would like to quickly remove the white space with a shortcut. This might be a neat function to add to WordService altogether. Preferably with the option to separate the words if there’s a capital letter in the string.

The RegEx for it: (?<=\s[\S+])\s(?=[\S+]\s*(?=(\s|,|\.|;)))(?![A-Z])

It’s not possible to extend WordService but it’s possible to create services via Automator, e.g. a shell script might apply the regex to the selected text that way.

To anyone how’s interested: it’s indeed very easy to implement. While I was on my way to fiddle with shell script, I found this even easier way to implement regex driven string manipulation with Alfred. Works like a charm.

And what if you’re not using Alfred? :thinking::stuck_out_tongue:

Then you’d be stuck with bin/bash, bin/zsh or something :sweat_smile:
Something along these lines with sed, awk, grep or perl:

echo "s t r i n g" | perl -pe 's/(?<=\s[\S+])\s(?=[\S+]\s*(?=(\s|,|\.|;)))(?![A-Z])//g'

that probably won’t work though

Are you referring to processing a single word like your echo shows?
If so - bearing in mind this is a very simple example to process…

echo "s t r i n g" | sed 's_ __g'
…or…
echo "s t r i n g" | tr -d ' '