当我复制这些数据时,我得到了这个结果:
R 1 -9.00
+0.03
G 2 -8.00
+0.36
F 3 -7.00
-0.26
每奇数行 3 列,以 a 开头[A-Z]
,然后是您想要的数据在下一行。
您想要的数字有两种形式:
^\t {3}([-+][0-9]+\.[0-9]{2})$ //for the red numbers
和:
^([-+][0-9]+\.[0-9]{2}) {3}\t$ //the green numbers
您可以像这样提取这两种类型:
^(\t {3})?([-+][0-9]+\.[0-9]{2})( {3}\t)?$
第二个捕获组([-+][0-9]+.[0-9]{2})
是您所追求的内容:
s/^(\t {3})?([-+][0-9]+\.[0-9]{2})( {3}\t)?$/$2/g
而不是 Applescript,请考虑 BBEdit 或Textwrangler,您可能会发现它们更易于使用。
将其放在搜索字段中:
\r[A-Z].*\r(\t {3})?([-+][0-9]+.[0-9]{2})( {3}\t)?$
这在替换:
\r\2
选择“全部替换”
这个怎么运作
\r // carriage return
[A-Z] // any character from A to Z (the lines you DON't want all start with a letter)
. // any character
* // any number of times
\r // carriage return
// that deals with the lines you DON't want to keep
( // grouping
\t // tab character
{3} // space character repeated 3 times
) // close grouping
? // zero or one occurences of the previous grouping
( // grouping (this is the bit you are after)
[+-] // character class - one of any of the [enclosed characters]
[0-9] // one of any of 0-9
+ // repeated one or more times
\. // full stop (escaped as it has special meaning in regext)
[0-9]{2} // exactly two occurences of any of 0-9
) // close capture parens (end of the group you are after)
( {3}\t)? // 3 spaces followed by a tab, occurring 0 or 1 time.
$ // end of line (in BBEdit/textwrangler you often use \r)
BBE/TW 中的重要细节,捕获的组被称为 \1,\2,\3,而不是 $1,$2,$3...</p>