如何删除匹配的行除了某些其他行?

时间:2017-01-03 17:46:50

标签: regex perl

如果我在变量中有以下内容

\item () $0.25$
  \item () $0.7$
\item 
  \item 

然后如何删除匹配\item的行,而不删除那些具有()集的行?

如果我这样做

$f =~ s|\\item.*?(?!\()||g;

然后由于某种原因删除所有\item

1 个答案:

答案 0 :(得分:6)

您正在搜索\item(后是否有\item () $0.25$ ^ ^^^^^^^^^ These positions aren't followed by "(" 后的位置。在所有情况下都有。

.*?

(?!)应位于s{ ^ .*? \\item (?! [^(\n]* \( ) .* \n }{}mgx

- (void) signInGoogleAnalytics {
id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];

// You only need to set User ID on a tracker once. By setting it on the tracker, the ID will be
// sent with all subsequent hits.
[tracker set:kGAIUserId
       value:self.txtStoreCode.text];


NSString *dimensionUsuarioLogado = [NSString stringWithFormat:@"%@", _txtEmployee.text];
NSString *dimensionLoja = [NSString stringWithFormat:@"%@", _txtStoreCode.text];

[tracker send:[[[GAIDictionaryBuilder createScreenView] set:dimensionUsuarioLogado
                                                     forKey:[GAIFields customDimensionForIndex:1]] build]];

[tracker send:[[[GAIDictionaryBuilder createScreenView] set:dimensionLoja
                                                     forKey:[GAIFields customDimensionForIndex:2]] build]];
}