[英]How to match and copy everything up to first occurrence of a character using regex?
Sample text format: 示例文本格式:
tom@yahoo.com,age:30|http://....
tom1@yahoo.com,age:31|http://....
tom2@yahoo.com,age:32|http://....
I want to match and copy everything before the '|'. 我想匹配并复制'|'之前的所有内容。 My regex:
^[^|]+
this will match everything up to the '|', how can I copy all the occurrences? 我的正则表达式:
^[^|]+
这将匹配所有'|',我该如何复制所有出现的内容?
2nd question Sample text format: 第二个问题示例文本格式:
tom@yahoo.com,age:30|100 lb
tom1@yahoo.com,age:31|200 lb
tom2@yahoo.com,age:32|300 lb
how can I match and copy all the text and range of 200 lb and below. 如何匹配和复制200磅及以下的所有文本和范围。 So the first two line should be extracted and copied.
因此,应该提取并复制前两行。
Regex : 正则表达式 :
(?m)^[^|]+
(?m)^[^|]+\\|\\b(?:[1]?[0-9][0-9]?|200)\\slb\\b
or (?m)^[^|]+\\|\\b(?:1?\\d\\d?|200)\\slb\\b
(?m)^[^|]+\\|\\b(?:[1]?[0-9][0-9]?|200)\\slb\\b
或(?m)^[^|]+\\|\\b(?:1?\\d\\d?|200)\\slb\\b
Details : 详细资料 :
(?m)
Multi line (?m)
多行 +
Matches between one and unlimited times +
无限次匹配 []
Match a single character present in the list []
匹配列表中存在的单个字符 [^]
Match a single character not present in the list [^]
匹配列表中不存在的单个字符 |
or \\d
matches a digit (equal to [0-9]
) \\d
匹配一个数字(等于[0-9]
) ?
Matches between zero and one times (?:)
Non-capturing group (?:)
非捕获组 \\s
Matches any whitespace character \\s
匹配任何空格字符
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.