Трудно быть уверенным в том, что вы хотите, опубликовать некоторые до и после примеров.И укажите, какой язык вы используете.
Но, похоже, (<-\S+)\s*(\S+->)
, вероятно, должен это делать (удаляет пробелы).
Если <-
и ->
НЕ предназначены длядля сохранения удалите их из круглых скобок, например так:
<-(\S+)\s*(\S+)->
Вот как это будет выглядеть в JavaScript:
var before = "Ten years ago a crack <-flegan esque-> unit was sent to prison by a military "
+ "court for a crime they didn't commit.\n"
+ "These men promptly escaped from a maximum security stockade to the "
+ "<-flargon 666-> underground.\n"
+ "Today, still wanted by the government, they survive as soldiers of fortune.\n"
+ "If you have a problem and no one else can help, and if you can find them, "
+ "maybe you can hire the <-flugen 9->.\n"
;
var after = before.replace (/(<-\S+)\s*(\S+->)/g, "$1$2");
alert (after);
Что дает:
Ten years ago a crack <-fleganesque-> unit was sent to prison by a military court for a crime they didn't commit.
These men promptly escaped from a maximum security stockade to the <-flargon666-> underground.
Today, still wanted by the government, they survive as soldiers of fortune.
If you have a problem and no one else can help, and if you can find them, maybe you can hire the <-flugen9->.