这一行:
anyWord = this is a placeholder to the end of line 我想删除anyWord =并获得该行的其余部分。
发布于 2021-05-02 15:03:45
如果您确定只希望使用正则表达式来解决此问题:
(?:^\w+ = )(.*)$
然后取捕获组(组1)。
发布于 2021-05-03 01:38:31
在不使用正则表达式的情况下,我们可以使用strtok在给定行中获取=字符的右侧:
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
const char* getRightSideOfEquals(const char* line){
char* linecopy = strdup(line);
const char* result = NULL;
char* left = strtok(linecopy, "=");
const char* right = strtok(NULL, "=");
while (right && isspace(*right)) { // remove whitespace
right++;
}
result = strdup(right ? right : "");
free((void*)linecopy);
return result;
}
int main()
{
const char* line = "anyWord = this is a placeholder to the end of line";
const char* right = getRightSideOfEquals(line);
printf("%s\n", right);
free((void*)right);
return 0;
}上面的程序将打印:this is a placeholder to the end of line
https://stackoverflow.com/questions/67353752
复制相似问题