我的问题涉及到“lookbehinds”,我想找到单词“this”后面的所有第一个数字,我有以下数据:
188282 this is an example of a number 12345 and 54321 188282 this is an example of a number 1234556 this is an example of a number 1234556 187293 this is another example of a number 74893 and 83978
模式:
this is an example of a number \d+
输出:
188282 this is an example of a number 12345 and 54321 188282 this is an example of a number 1234556 this is an example of a number 1234556 187293 this is another example of a number 74893 and 83978
为了匹配它们,我使用了更通用的方法,因为我知道我想要在单词“this”后面的第一个数字
模式:
this[^\d]+\d+
输出:
188282 this is an example of a number 12345 and 54321 188282 this is an example of a number 1234556 this is an example of a number 1234556 187293 this is another example of a number 74893 and 83978
现在我尝试使用lookbehind,因为我不想在结果中包含模式的一部分。按照我的第一种方法:
模式:
(?<=this is an example of a number )\d+
输出:
188282 this is an example of a number 12345 and 54321 188282 this is an example of a number 1234556 this is an example of a number1234556 187293 this is another example of a number 74893 and 83978
看起来我正在接近目标,我想像之前一样覆盖最后一种情况,所以我尝试了我的第二种方法。
模式:
(?<=this[^\d]+)\d+
输出:
188282 this is an example of a number 12345 and 54321 188282 this is an example of a number 1234556 this is an example of a number 1234556 187293 this is another example of a number 74893 and 83978
188282 this is an example of a number 12345 and 54321 188282 this is an example of a number 1234556 this is an example of a number 1234556 187293 this is another example of a number 74893 and 83978
模式:
this is an example of a number \d+
输出:
188282 this is an example of a number 12345 and 54321 188282 this is an example of a number 1234556 this is an example of a number 1234556 187293 this is another example of a number 74893 and 83978
为了匹配它们,我使用了更通用的方法,因为我知道我想要在单词“this”后面的第一个数字
模式:
this[^\d]+\d+
输出:
188282 this is an example of a number 12345 and 54321 188282 this is an example of a number 1234556 this is an example of a number 1234556 187293 this is another example of a number 74893 and 83978
现在我尝试使用lookbehind,因为我不想在结果中包含模式的一部分。按照我的第一种方法:
模式:
(?<=this is an example of a number )\d+
输出:
188282 this is an example of a number 12345 and 54321 188282 this is an example of a number 1234556 this is an example of a number1234556 187293 this is another example of a number 74893 and 83978
看起来我正在接近目标,我想像之前一样覆盖最后一种情况,所以我尝试了我的第二种方法。
模式:
(?<=this[^\d]+)\d+
输出:
188282 this is an example of a number 12345 and 54321 188282 this is an example of a number 1234556 this is an example of a number 1234556 187293 this is another example of a number 74893 and 83978
没有匹配的内容
在回顾后面是否可能有模式?我是不是对这个问题采取了错误的方法?这有点长,但我想向您展示我迄今为止尝试过的东西,而不是仅仅问问题
提前感谢