如果您使用的是TextMate,那么您使用的是Mac,因此使用Python。
尝试这个:
#!/usr/bin/env python
import re
input = open('test.html', 'r')
p_spaces = re.compile(r'^.*rel="[^"]+".*$')
for line in input:
matches = p_spaces.findall(line)
for match in matches:
new_rel = match.replace(' ', '_')
line = line.replace(match, new_rel)
print line,示例输出:
$ cat test.html
testing, testing, 1, 2, 3
Stuff
aoseuaoeua
$ ./test.py
testing, testing, 1, 2, 3
Stuff
aoseuaoeua