0
이 텍스트가 있다고 가정 해보십시오.어떤 코멘트가 좋은 정규 표현식인가? Syntax Highlighting?
word1 word2 " word3 //" word4
주석을 위해 regexp를 작성해야합니다. 내 솔루션은 이제 ((\/\/).*(\n))
((\").*(\"))
이 텍스트가 있다고 가정 해보십시오.어떤 코멘트가 좋은 정규 표현식인가? Syntax Highlighting?
word1 word2 " word3 //" word4
주석을 위해 regexp를 작성해야합니다. 내 솔루션은 이제 ((\/\/).*(\n))
((\").*(\"))
그것은 내 솔루션입니다 ""텍스트에 대한
정규 표현식 결과 ((\/\/).*(\n))
이다. 나는 그것이 더 좋다는 것을 안다. 나에 대해 알고 위로 참조하지만 난 그것에 경험이 없어.
NSRegularExpression *exp = [NSRegularExpression regularExpressionWithPattern:@"((@\"|\").*?(\"))"
options:NSRegularExpressionDotMatchesLineSeparators
error:nil];
NSArray *textArr = [exp matchesInString:string options:0 range:NSMakeRange(0, [string length])];
for (NSTextCheckingResult *result in textArr) {
// set color for range
}
// Comments
exp = [NSRegularExpression regularExpressionWithPattern:@"(//[^\"\n]*)"
options:0
error:nil];
NSArray * arrayComments = [exp matchesInString:string options:0 range:NSMakeRange(0, [string length])];
for (NSTextCheckingResult *resultComment in arrayComments) {
BOOL inside = NO;
for (NSTextCheckingResult *resultText in textArr) {
NSInteger from = resultText.range.location;
NSInteger to = resultText.range.location+resultText.range.length;
NSInteger now = resultComment.range.location;
if (from < now && now < to) {
inside = YES;
break;
}
}
if (!inside) {
// set color for range
}
}