查找内容:(?s)\b(X\d{2})(?:(?!X\d{2}).)*["\s]([^"\s]+\.dun)|(?:(?!X\d{2}).)*替换为:(?{1}$1\t\t$2\n)请参见 regex模式演示. 详细信息: (?s)-DOTALL修饰符(您可以将其删除并检查 .匹配换行符选项) \b-与单词开头的X匹配的前导单词边界 (X\d{2})-捕获X的第1组(请注意,如果您不想匹配小写字母x,则必须打开 Match Case )和任意两位数字 (?:(?!X\d{2}).)*-与任何字符(零个或多个重复)匹配的经过调节的贪婪令牌,其后没有X和任何两位数字.由于它是贪婪的,它将补足到下一个字符开始禁止序列的位置,并将回溯到后续子模式所需的最后一个墩". ["\s]-空格或双引号 ([^"\s]+\.dun)-组2捕获除空格和双引号之外的一个或多个字符,然后是一个点和一个dun子字符串 |-或 (?:(?!X\d{2}).)*-与上述相同的调和贪婪令牌. 替换详细信息: (?{1}-如果第1组匹配... $1\t\t$2\n-替换为第一个组值,两个选项卡,第二个组值和换行符 )-否则替换为空字符串. I am trying to match and get the last occurrence of a pattern in my file using notepad++.My text:X12Source =asdjkasjd file="x/y1.dun" "x/y2.dun" "x/y3.dun"asds12 X22 p/q/xy.dunasda=23source =asdf X4410001001 file="abc.dun"What I expect using find-and-replace is this:X12 x/y3.dunX22 p/q/xy.dunX44 abc.dunWhat I have tried so far:(X\d{2}).*?([^"\s]+dun)((?!X\d{2}).)*replace with:$1\t\t$2\nBut it returns me this:X12 x/y1.dun //Which is the first matchX22 p/q/xy.dunX44 abc.dunHow do I get the last match inside a match? I am looking for a general way for getting the last match. 解决方案 You may match and capture what you need to keep and just match what you do not need, and only replace with text when a capture group is matched:Find What: (?s)\b(X\d{2})(?:(?!X\d{2}).)*["\s]([^"\s]+\.dun)|(?:(?!X\d{2}).)*Replace With: (?{1}$1\t\t$2\n)See the regex pattern demo.Details:(?s) - a DOTALL modifier (you may remove it and check the . matches newline option)\b - a leading word boundary to match X at the start of a word(X\d{2}) - Group 1 capturing a X (note that Match Case must be turned on if you do not want to match a lowercase x) and any two digits(?:(?!X\d{2}).)* - a tempered greedy token matching any char, zero or more repetitions, that is not followed with X and any two digits. Since it is greedy, it will make it up to the location where the next character starts the forbidden sequence and will backtrack to the last "dun" required by the subsequent subpattern.["\s] - a whitespace or a double quote([^"\s]+\.dun) - Group 2 capturing one or more chars other than whitespace and double quote, then a dot and a dun substring| - or(?:(?!X\d{2}).)* - the same tempered greedy token as above.Replacement details:(?{1} - if Group 1 matched....$1\t\t$2\n - replace with the first group value, two tabs, the second group value and a newline) - else replace with an empty string. 这篇关于从多个比赛中获取最后一场比赛的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-08 18:42