我想展示一下我可以用制表符替换空格缩进,但只显示每行的前导空格。
我想我可以通过可变宽度的后视来实现这一点。不幸的是,PCRE不允许这样做。
s/(?<=^|(?:[ ]{3})+)[ ]{3}(?=\S|(?:[ ]{3})+\S)/\t/g
还有其他办法吗?
当然,一般的想法是不要通过重复替换来做循环。这太容易了......
以下是随机输入的示例,其中必须将2个空格转换为制表符:
if (c == 1&d == 2){
for (uinc = 1;uinc< = p1;uinc++){ // for fixed u calculate various w's
if (1.0-u<5e-6)u = 1.0; // fix up the u = 1 value because of float
w = 0.0;
for (winc = 1;winc< = p2;winc++){
if (1.0-w<5e-6)w = 1.0; // fix up the w = 1 value because of float
for (i = 0;i< = n;i++){
jin = Basis(n,i,u); // Bernstein basis function in the u direction (see Eq.(5.2))
if (jin! = 0.){ // don't bother no contribution
jbas = 3*(m+1)*i; /* column index for lineal array*/
for (j = 0;j< = m;j++){
kjm = Basis(m,j,w); // Bernstein basis function in the w direction (see Eq.(5.2))
if (kjm! = 0.){ // don't bother no contribution
j1 = jbas+3*j+1;
q[icount] = q[icount]+b[j1]*jin*kjm; // calculate the surface points
q[icount+1] = q[icount+1]+b[j1+1]*jin*kjm;
q[icount+2] = q[icount+2]+b[j1+2]*jin*kjm;
}
}
}
}
icount += 3;
w = w+stepw;
}
u += stepu;
}
}
}