English 中文(简体)
在两条街之间添加可变的白色空间
原标题:Adding variable whitespace between two strings
  • 时间:2012-04-25 20:49:34
  •  标签:
  • regex

我没有使用编码语言。 这必须是直截了当的。

我需要在两条楼之间增加一个可变的白空间。 我在座的座右边有白色空间,需要替换:

string1 *27* string2

因此,我需要把27个白色空间插入插在座1至2号之间。

*(d+)*

这是我所抓住的,它似乎正在发挥作用,但我正试图把我改为:

s{$1}

$&s{$1}

因此,你会怎样做? 我正在使用口号进行验证,但并非所有的雷管模式都得到我使用的文字发动机的支持。

最佳回答

这样做是不可能的。 雷切尔将需要某种平级能力,以利用所捕获的变量并将其转化为重复空间。

你想要替代工作的方式也是不可能的。 由于reg鱼的替换部分是直截了当的,而不是另一个reg蒸器。

问题回答

使用<代码>perl的一种方式 惠制:

perl -e  
  $s = q[string1 *27* string2]; 
  $s =~ s/s+*(d+)*s+/" " x $1/e; 
  print $s
 

产出:

string1                           string2




相关问题
Uncommon regular expressions [closed]

Recently I discovered two amazing regular expression features: ?: and ?!. I was curious of other neat regex features. So maybe you would like to share some tricky regular expressions.

regex to trap img tag, both versions

I need to remove image tags from text, so both versions of the tag: <img src="" ... ></img> <img src="" ... />

C++, Boost regex, replace value function of matched value?

Specifically, I have an array of strings called val, and want to replace all instances of "%{n}%" in the input with val[n]. More generally, I want the replace value to be a function of the match ...

PowerShell -match operator and multiple groups

I have the following log entry that I am processing in PowerShell I m trying to extract all the activity names and durations using the -match operator but I am only getting one match group back. I m ...

Is it possible to negate a regular expression search?

I m building a lexical analysis engine in c#. For the most part it is done and works quite well. One of the features of my lexer is that it allows any user to input their own regular expressions. This ...

regex for four-digit numbers (or "default")

I need a regex for four-digit numbers separated by comma ("default" can also be a value). Examples: 6755 3452,8767,9865,8766,3454 7678,9876 1234,9867,6876,9865 default Note: "default" ...

热门标签