如何使用正则表达式进行大规模更改

时间:2015-03-22 15:19:47

标签: regex


Live! => [ cambax83@gmail.com:xxxxx ] + [Name: Cameron - Following: 225 - Follower: 2 - Bio: GAFY - Location: Australia - URL: Empty - Translator: No - Verified: No (Joined At Wed Oct 12 21:54:04 +0000 2011 [1256 Days])]
Live! => [ kingrozny@hotmail.com:xxxxx ] + [Name: Edgar - Following: 236 - Follower: 9 - Bio: Empty - Location: Empty - URL: Empty - Translator: No - Verified: No (Joined At Sun Jan 15 07:45:52 +0000 2012 [1162 Days])]
Live! => [ voonshin@gmail.com:xxxxx ] + [Name: Voonshin - Following: 381 - Follower: 1 - Bio: Empty - Location: Empty - URL: Empty - Translator: No - Verified: No (Joined At Thu Sep 20 04:14:04 +0000 2012 [913 Days])]
Live! => [ y0ng4n@gmail.com:xxxxx ] + [Name: Surabaya Jaya - Following: 539 - Follower: 0 - Bio: Surabaya Jaya merupakan Distributor Peralatan Safety, Sarung tangan, Terpal, dsb. Distributor kita berpusat di kota Surabaya dan memiliki cabang di Balikpapan. - Location: Balikpapan - URL: Empty - Translator: No - Verified: No (Joined At Fri Aug 01 11:38:33 +0000 2014 [233 Days])]
Live! => [ Honeybee104@hotmail.com:xxxxx ] + [Name: Diane - Following: 84 - Follower: 1 - Bio: Empty - Location: Empty - URL: Empty - Translator: No - Verified: No (Joined At Fri Jul 25 23:03:26 +0000 2014 [239 Days])]

之后:

cambax83@gmail.com:xxxxx
kingrozny@hotmail.com:com:xxxxx
voonshin@gmail.com:com:xxxxx
y0ng4n@gmail.com:com:xxxxx
Honeybee104@hotmail.com:com:xxxxx

如何使用正则表达式进行大规模清洁,请使用https://regex101.com/上的演示! :)

3 个答案:

答案 0 :(得分:0)

根据糟糕的规范,我会https://regex101.com/r/mI4mJ6/1

\[\s*(.*xxxx) \]

答案 1 :(得分:0)

查找^[^\[]*\[\s*|\s*\].*$

<强>替换Empty string

试试这个。看看演示。

https://regex101.com/r/pT4tM5/32

http://regexr.com/3alde

答案 2 :(得分:0)

在此处查看演示https://regex101.com/r/cN7vT8/1

/(\w+@\w+\.\w{2,4}:xxxxx)/gm

并在此处替换演示https://regex101.com/r/cN7vT8/2

var re = /.*\[ (\w+@\w+\.\w{2,4}:xxxxx).*/gm; 
var subst = '$1';  
var result = str.replace(re, subst);