How to delete all space to left and right of asterisk* (Find&Replace)?

My document has lines like:
1 Some words here████████ * ███some more words.
2 Some words here██ * ████123 some more words.

(There is irregular empty space around the asterisk *. Please pretend the █ are empty spaces, as I couldn’t do multiple empty spaces here on this forum, it auto-corrects them as a single space.)

How can I Find&Replace (just find in this case, of course) whatever space there is on each side of the asterisk before some characters (alphaNUMeric) start? so I can delete all empty space around the asterisks *.

Use regular expressions. In Find: enter \s+\*\s+ and in Replace: " * " (single space, asterisk, single space, without the quotes).

A few words of explanations:

  • \s+ is spacer \s repeated at least once +
    Note that this is wider than your specification because \s will also match tab characters. If you don’t want this to happen, replace \s with “ ” (single space, without the quotes).
  • \*: the reverse solidus \ is necessary to escape * because it has special meaning in regular expressions

If you want to delete spaces, just don’t enter them in the Replace: string.

1 Like