さて、ここに行きます:
var s = "Nelly Thomas (Approve) 12/27/2012 8:50 PM - 12/27/2012 8:52 PM\n\
(Nelly Thomas) LazyApproval by nelly.thomas@joshworld.local Approved\n\
\n\
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, \n\
when an unknown printer took a galley of type and scrambled it to make a type specimen book";
s.replace(/(.+)\(.+\)\s((\d\d\/){2}\d{4}\s\d{1,2}:\d\d\s\w\w)\s-\s.+[\n|\r].+[\n|\r]{2}([^]+)/gi, '$1$2\n\n$4');
//Result:
"Nelly Thomas 12/27/2012 8:50 PM
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,
when an unknown printer took a galley of type and scrambled it to make a type specimen book"
これは有効な正規表現ですが、特にきれいではありません。
# / --> Regex start:
# (.+) --> a word (group #1)
# \(.+\)\s --> followed by a word in () and a space.
# ((\d\d\/){2}\d{4}\s --> followed by a date and
# \d{1,2}:\d\d\s\w\w) --> time (group #2)
# \s-\s --> followed by ` - `
# .+ --> followed by any number of letters or spaces. (The 2nd date)
# [\n|\r] --> followed by a newline.
# .+ --> followed by any number of letters or spaces. (The 2nd line)
# [\n|\r]{2} --> followed by 2 newlines.
# ([^]+) --> followed by _any_ character, including newlines (group 4)
# /gi --> Regex end, (g)lobal flag, case (i)nsensitive flag.
次に、との間に二重改行を入れて、グループとを出力し1
ます。2
4
2
4
したがって、醜いですが、テキストが次の形式に従っている限り、機能します。
W(W)DD \ DD \ DDDD D(?D):DD LL-W
W
W
ここD
で、は1桁、L
は文字、W
は改行を除く任意の数の単語とスペースであり、D(?D)
1桁または2桁を意味します。