0

Whenever english character of length 1 exists, I want that to be combined with the previous text.

gsub('(.*)\\s+([a-zA-Z]{1})', "\\1\\2", 'Anti-Candida a ингибинов')

Anti-Candidaa ингибинов

For the example below, it should return 'Anti-Candida am ингибинов' as 'am' is of length 2.

gsub('(.*)\\s+([a-zA-Z]{1})', "\\1\\2", 'Anti-Candida am ингибинов')
john
  • 1,026
  • 8
  • 19

1 Answers1

1

You can use this regex:

\W+([a-zA-Z])\b

replace with \\1. The trick here is to match a word boundary after the single letter.

Demo

Your regex will work as well, if you just add that \b at the end.

Sweeper
  • 213,210
  • 22
  • 193
  • 313