Thread View: cn.comp.os.linux
7 messages
7 total messages
Started by Moses
Sat, 12 Sep 2009 10:51
��һ��������ʽ����ôд
Author: Moses
Date: Sat, 12 Sep 2009 10:51
Date: Sat, 12 Sep 2009 10:51
20 lines
2603 bytes
2603 bytes
数据每个一行, 比如是一些邮件地址 aaa@gmail.com bbb@gmail.com ... ... ccc@163.com ddd@yahoo.com eee@hotmail.com 现在想将所有不包含某字段 (比如非 Gmail 的) 的行替换为空行, 正则表达式应该怎么写? 我试了 [^gmail.com]$ 但是只能匹配部分, 像是 @163.com 结尾的就跳过了, 不知道什么原因 谢谢
Re: 问一句正则表达式该怎么写
Author: NewBlue
Date: Sat, 12 Sep 2009 17:19
Date: Sat, 12 Sep 2009 17:19
25 lines
1722 bytes
1722 bytes
����ʲô���ߣ� ������grep�� [newblue@hackit ~]$ cat Moses > ���ÿ��һ��, ������һЩ�ʼ���ַ > aaa@gmail.com > bbb@gmail.com > ... > ... > ccc@163.com > ddd@yahoo.com > eee@hotmail.com > > �����뽫���в���ij�ֶ� (����� Gmail ��) �����滻Ϊ����, ������ʽӦ����ôд? > ������ [^gmail.com]$ ����ֻ��ƥ�䲿��, ���� @163.com ��β�ľ������, ��֪��ʲôԭ�� > > лл > -- http://www.life-maker.cn/ ��֪��Ѱ������Ҫ����ܶ�����ѣ����һ�Ŭ����
Re: ��һ��������ʽ����ôд
Author: Moses
Date: Sun, 13 Sep 2009 01:03
Date: Sun, 13 Sep 2009 01:03
41 lines
3419 bytes
3419 bytes
用 Emcas 和 notepad++, 但在 Windows 下, 没 grep... -- 楼上 NewBlue 说的 "Re: 问一句正则表达式该怎么写" 在某一分钟的第 17 秒被 Moses 所回复; 文件夹 ID 为 58; 原帖 25 行共 1295 字节. N> 你用什么工具? N> 试试用grep! N> [newblue@hackit ~]$ cat Moses >> 数据每个一行, 比如是一些邮件地址 >> aaa@gmail.com >> bbb@gmail.com >> ... >> ... >> ccc@163.com >> ddd@yahoo.com >> eee@hotmail.com >> >> 现在想将所有不包含某字段 (比如非 Gmail 的) 的行替换为空行, 正则表达式应该怎么写? >> 我试了 [^gmail.com]$ 但是只能匹配部分, 像是 @163.com 结尾的就跳过了, 不知道什么原因 >> >> 谢谢 >>
Re: 问一句正则表达式该怎么写
Author: Li
Date: Sun, 13 Sep 2009 01:46
Date: Sun, 13 Sep 2009 01:46
12 lines
2114 bytes
2114 bytes
M-x keep-lines RET gmail RET ?? see http://www.delorie.com/gnu/docs/emacs/emacs_104.html you may also try list-matching-lines (works on whole file) delete-matching-lines (works on region if exist, else work from cursor point to end of file.) delete-non-matching-lines On Sep 12, 6:51 pm, "Moses" <moses.ma...@gmail.com> wrote: > 数据每个一行, 比如是一些邮件地址 > a...@gmail.com > b...@gmail.com > ... > ... > c...@163.com > d...@yahoo.com > e...@hotmail.com > > 现在想将所有不包含某字段 (比如非 Gmail 的) 的行替换为空行, 正则表达式应该怎么写? > 我试了 [^gmail.com]$ 但是只能匹配部分, 像是 @163.com 结尾的就跳过了, 不知道什么原因 > > 谢谢
Re: ��һ��������ʽ����ôд
Author: Moses
Date: Sun, 13 Sep 2009 05:53
Date: Sun, 13 Sep 2009 05:53
45 lines
3522 bytes
3522 bytes
ya, 成功了, thanks~ -- 楼上 Li 说的 "Re: 问一句正则表达式该怎么写" 在某一分钟的第 32 秒被 Moses 所回复; 文件夹 ID 为 58; 原帖 12 行共 2128 字节. L> M-x keep-lines RET gmail RET ?? L> see L> http://www.delorie.com/gnu/docs/emacs/emacs_104.html you may also try L> list-matching-lines (works on whole file) L> delete-matching-lines (works on region if exist, else work from cursor L> point to end of file.) L> delete-non-matching-lines L> On Sep 12, 6:51 pm, "Moses" <moses.ma...@gmail.com> wrote: > 数据每个一行, 比如是一些邮件地址 >> a...@gmail.com >> b...@gmail.com >> ... >> ... >> c...@163.com >> d...@yahoo.com >> e...@hotmail.com >> >> 现在想将所有不包含某字段 (比如非 Gmail 的) 的行替换为空行, 正则表达式应该怎么写? >> 我试了 [^gmail.com]$ 但是只能匹配部分, 像是 @163.com 结尾的就跳过了, 不知道什么原因 >> >> 谢谢
Re: ��һ��������ʽ����ôд
Author: Moses
Date: Sun, 13 Sep 2009 05:54
Date: Sun, 13 Sep 2009 05:54
87 lines
4636 bytes
4636 bytes
就处理一个文件, 不想写程序了.............
还是谢谢了~
--
楼上 Luo 说的 "Re: 问一句正则表达式该怎么写" 在某一分钟的第 15 秒被 Moses 所回复;
文件夹 ID 为 58;
原帖 64 行共 2376 字节.
LY> Java版:
LY> =====>>>
LY> package testjava;
LY> import java.io.BufferedReader;
LY> import java.io.File;
LY> import java.io.FileInputStream;
LY> import java.io.InputStreamReader;
LY> import java.util.regex.Pattern;
LY> /**
LY> *
LY> * @author yong
LY> */
LY> public class Main {
LY> /**
LY> * @param args the command line arguments
LY> */
LY> public static void main(String[] args) {
LY> // Text file contains the mail addresses.
LY> File inputFile = new File("/home/yong/text.txt");
LY> try {
LY> FileInputStream input = new FileInputStream(inputFile);
LY> InputStreamReader inputReader = new
LY> InputStreamReader(input);
LY> BufferedReader reader = new BufferedReader(inputReader);
LY> String line = reader.readLine();
LY> while(line != null) {
LY> line = line.trim();
LY> // Print the line if matched.
LY> if (!Pattern.matches("^.*?@gmail.com.*?$", line)) {
LY> System.out.println(line);
LY> }
LY> line = reader.readLine();
LY> }
LY> }catch(Exception e) {
LY> e.printStackTrace(System.err);
LY> }
LY> }
LY> }
LY> =====<<<
LY> "Moses" <moses.mason@gmail.com> writes:
>> 数据每个一行, 比如是一些邮件地址
>> aaa@gmail.com
>> bbb@gmail.com
>> ...
>> ...
>> ccc@163.com
>> ddd@yahoo.com
>> eee@hotmail.com
>>
>> 现在想将所有不包含某字段 (比如非 Gmail 的) 的行替换为空行, 正则表达式应该怎么写?
>> 我试了 [^gmail.com]$ 但是只能匹配部分, 像是 @163.com 结尾的就跳过了, 不知道什么原因
>>
>> 谢谢
Re: 问一句正则表达式该怎么写
Author: Luo Yong
Date: Sun, 13 Sep 2009 19:12
Date: Sun, 13 Sep 2009 19:12
64 lines
2719 bytes
2719 bytes
Java�棺
=====>>>
package testjava;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.regex.Pattern;
/**
*
* @author yong
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// Text file contains the mail addresses.
File inputFile = new File("/home/yong/text.txt");
try {
FileInputStream input = new FileInputStream(inputFile);
InputStreamReader inputReader = new InputStreamReader(input);
BufferedReader reader = new BufferedReader(inputReader);
String line = reader.readLine();
while(line != null) {
line = line.trim();
// Print the line if matched.
if (!Pattern.matches("^.*?@gmail.com.*?$", line)) {
System.out.println(line);
}
line = reader.readLine();
}
}catch(Exception e) {
e.printStackTrace(System.err);
}
}
}
=====<<<
"Moses" <moses.mason@gmail.com> writes:
> ���ÿ��һ��, ������һЩ�ʼ���ַ
> aaa@gmail.com
> bbb@gmail.com
> ...
> ...
> ccc@163.com
> ddd@yahoo.com
> eee@hotmail.com
>
> �����뽫���в���ij�ֶ� (����� Gmail ��) �����滻Ϊ����, ������ʽӦ����ôд?
> ������ [^gmail.com]$ ����ֻ��ƥ�䲿��, ���� @163.com ��β�ľ������, ��֪��ʲôԭ��
>
> лл
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads