# WordService Extension: Remove white space

**URL:** <https://discourse.devontechnologies.com/t/wordservice-extension-remove-white-space/46059>\
**Category:** Needful things\
**Created:** [April 1, 2019, 12:15pm UTC](https://discourse.devontechnologies.com/t/wordservice-extension-remove-white-space/46059 "2019-04-01T12:15:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![zeitlings](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/zeitlings/32/7277_2.png) [@zeitlings](https://discourse.devontechnologies.com/u/zeitlings)\
**Post date:** [April 1, 2019, 12:15pm UTC](https://discourse.devontechnologies.com/t/wordservice-extension-remove-white-space/46059/1 "2019-04-01T12:15:37Z")

</div>

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])`

---

<div class="post-metadata">

**Author:** ![cgrunenberg](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/cgrunenberg/32/7172_2.png) [@cgrunenberg](https://discourse.devontechnologies.com/u/cgrunenberg)\
**Post date:** [April 1, 2019, 12:31pm UTC](https://discourse.devontechnologies.com/t/wordservice-extension-remove-white-space/46059/2 "2019-04-01T12:31:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![zeitlings](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/zeitlings/32/7277_2.png) [@zeitlings](https://discourse.devontechnologies.com/u/zeitlings)\
**Post date:** [June 1, 2019, 12:42pm UTC](https://discourse.devontechnologies.com/t/wordservice-extension-remove-white-space/46059/3 "2019-06-01T12:42:01Z")

</div>

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](https://www.alfredapp.com/blog/tips-and-tricks/manipulating-selected-text-in-macos-with-alfred-workflows/). Works like a charm.

---

<div class="post-metadata">

**Author:** ![BLUEFROG](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/bluefrog/32/135_2.png) [@BLUEFROG](https://discourse.devontechnologies.com/u/BLUEFROG)\
**Post date:** [June 1, 2019, 4:12pm UTC](https://discourse.devontechnologies.com/t/wordservice-extension-remove-white-space/46059/4 "2019-06-01T16:12:17Z")

</div>

And what if you’re not using Alfred? 🤔😛

---

<div class="post-metadata">

**Author:** ![zeitlings](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/zeitlings/32/7277_2.png) [@zeitlings](https://discourse.devontechnologies.com/u/zeitlings)\
**Post date:** [June 1, 2019, 4:55pm UTC](https://discourse.devontechnologies.com/t/wordservice-extension-remove-white-space/46059/5 "2019-06-01T16:55:10Z")

</div>

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

```auto
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

---

<div class="post-metadata">

**Author:** ![BLUEFROG](https://discourse.devontechnologies.com/user_avatar/discourse.devontechnologies.com/bluefrog/32/135_2.png) [@BLUEFROG](https://discourse.devontechnologies.com/u/BLUEFROG)\
**Post date:** [June 1, 2019, 5:58pm UTC](https://discourse.devontechnologies.com/t/wordservice-extension-remove-white-space/46059/6 "2019-06-01T17:58:09Z")

</div>

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 ' '`
