简体   繁体   English

正则表达式记事本++

[英]Regular Expressions Notepad++

When using character delimited text, what code allows me to pull out specific segments within a given row?使用字符分隔文本时,哪些代码允许我提取给定行中的特定段? Out of a given set of data (focusing on bold):在给定的一组数据中(重点是粗体):

1194459945, 11/07/2007 18:25:45,2,vnta,287.78,2, 7.783 ,2,34.111,2,1.3,2, 89.54 ,2,1485.31,26.612 1194459945,2007年11月7日18:25:45,2,vnta,287.78,2,7.783,2,34.111,2,1.3,2,89.54,2,1485.31,26.612

Trying to get it like:试图得到它像:

11/07/2007 7.783 89.54 11/07/2007 7.783 89.54

Currently, the progress I've made has been: (\\w+,)(.+) ( which has given me the first two columns, but I'm stuck as to how to reach 7.783 and segment that out. Without including the entire row. I cannot put \\, because that doesn't help.目前,我取得的进展是: (\\w+,)(.+) (它给了我前两列,但我不知道如何达到 7.783 并将其分割出来。不包括整个行。我不能放\\,因为那没有帮助。

Something like this might work.. ^.*?,([^ ,]+)(?:.*?,){5}([^ ,]+)(?:.*?,){6}([^ ,]+).*$这样的事情可能会起作用.. ^.*?,([^ ,]+)(?:.*?,){5}([^ ,]+)(?:.*?,){6}([^ ,]+).*$

Explanation:解释:

  • ^ - Start of the string / line ^ - 字符串/行的开始
  • .*?, - matches anything up until the first comma .*?, - 匹配任何直到第一个逗号
  • ([^ ,]+) - matches anything not a space or comma and stores it in capture group 1 (your date) ([^ ,]+) - 匹配任何不是空格或逗号的内容并将其存储在捕获组 1 (您的日期)中
  • (?:.*?,){5} - non capture group to match the fields and commas for the next 5 fields (?:.*?,){5} - 非捕获组以匹配接下来 5 个字段的字段和逗号
  • ([^ ,]+) - matches anything not a space or comma and stores it in capture group 2 (your 7.783) ([^ ,]+) - 匹配任何不是空格或逗号的内容并将其存储在捕获组 2 (您的 7.783)中
  • (?:.*?,){6} - another non capture group to match the fields and commas for the next 6 fields (?:.*?,){6} - 另一个非捕获组,用于匹配接下来 6 个字段的字段和逗号
  • ([^ ,]+) - matches anything not a space or comma and stores it in capture group 3 (your 89.54) ([^ ,]+) - 匹配任何不是空格或逗号的内容并将其存储在捕获组 3 (您的 89.54)中
  • .*$ - matches anything trailing after this match to the end of string / line .*$ - 匹配此匹配之后到字符串/行末尾的任何内容

Notepad++:记事本++:

You can use the find and replace tool in Notepad++ to replace the strings with only the capture groups which can be accessed by using a dollar sign followed by the capture group number like so:您可以使用 Notepad++ 中的查找和替换工具将字符串替换为可以通过使用美元符号后跟捕获组编号访问的捕获组,如下所示:

Find: ^.*?,([^ ,]+)(?:.*?,){5}([^ ,]+)(?:.*?,){6}([^ ,]+).*$
Replace: $1 $2 $3

Test:测试:

Before:前:

1194459945,11/07/2007 18:25:45,2,vnta,287.78,2,7.783,2,34.111,2,1.3,2,89.54,2,1485.31,26.612

After:后:

11/07/2007 7.783 89.54

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM