【发布时间】:2016-01-13 08:42:17
【问题描述】:
我正在使用此代码来缩进一段文本。它工作正常,但它在末尾添加了空白。
public var indentPattern:RegExp = /([\t ]*)(.*)$/gm;
public function indent(input:String, indentAmount:String = "\t"):String {
if (input==null || input=="") return indentAmount;
var indentedText:String = input.replace(indentPattern, indentAmount + "$1$2");
return indentedText;
}
测试输入数据:
<style type="text/css">
html, body {
height:100%;
margin:0;
padding:0;
line-height:.8;
}
*, *:before, *:after {
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
box-sizing:border-box;
}
</style>
实际输出:
<style type="text/css">
html, body {
height:100%;
margin:0;
padding:0;
line-height:.8;
}
*, *:before, *:after {
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
box-sizing:border-box;
}
</style>
注意:当我说末尾的空格时,制表符是在分号后的行尾添加的。尝试突出显示页面上的文本以查看我在说什么。
【问题讨论】:
标签: javascript regex actionscript-3