我有一个字符串模式,如" test" :" abc / gef fhhff / fhrhr krerjr",
我想替换以" test"开头的行中的所有空格。加号。如何使用正则表达式?
答案 0 :(得分:0)
在perl中,您必须执行以下操作:
use strict;
use warnings;
use 5.010;
my $text = q|test : "abc/gef fhhff/fhrhr krerjr"|;
#below is the regex that does the replace - \s is for whitespace class
$text =~ s/\s/+/gmix if ( $text =~ /^test/gmix);
say "new text: $text";
答案 1 :(得分:0)
for vb net try
Dim strCurrentLine as string = "test : abc/gef fhhff/fhrhr krerjr"
If UCase(strCurrentLine.ToString.StartsWith("TEST")) = True Then
strCurrentLine = Replace(strCurrentLine.ToString, " ", "Replace space with this text")
End If
for C#try
string strCurrentLine = "test : abc/gef fhhff/fhrhr krerjr";
if (Strings.UCase(strCurrentLine.ToString().StartsWith("TEST")) == true) {
strCurrentLine = Strings.Replace(strCurrentLine.ToString(), " ", "Replace space with this text");
}
或者转到vb正则表达式http://visualbasic.about.com/od/usingvbnet/a/RegExNET_2.htm
或者去c#regex http://oreilly.com/windows/archive/csharp-regular-expressions.html