标签:
查找边界
line_text.endswith(‘my_case_‘): line_text.startswith(‘my_case_‘)
查找子字符串
url.find(‘show)
文字提取
re.compile(r‘\s+(\d+):.*‘) .sub(r‘\1‘,line_text) # 直接截取,截取不到也会返回字符串
打开文件,并更新
open(‘testone_config.json‘,‘w‘).write(‘sublime text’)
测试url是否有效
import urllib.request url=‘http://www.baidu.com‘ try: urllib.request.urlopen(urllib.request.Request(url)) except : sublime.status_message(‘ url无效! ‘)
获取单词
# view 视频,self.view # mark 要查找的一个点 def get_word(view,mark,one=True): func=‘‘ mark_line=view.line(mark.a) func_a = view.substr( sublime.Region(mark_line.a,mark.a) ) func_b = view.substr( sublime.Region(mark.a,mark_line.b) ) back_b=re.findall(r‘(^[ma\w_]+)[\"\‘\(]‘,func_b) back_a=re.findall(r‘[\"\‘>\.\s]([\w_]+)$‘,func_a) if one: if back_a and back_b: func = back_a[0] + back_b[0] else: if back_a : func= back_a[0] if back_b : func+= back_b[0] return func
对页面的批处理替换
class func_tihuan_allCommand(sublime_plugin.TextCommand): def run(self,edit,tr): mark = self.view.sel()[0] func = self.view.substr( mark ) if tr==‘tp‘: func = func.replace(‘src="images/‘, ‘src="__PUBLIC__/home/Img/‘) func = func.replace(‘src="js/‘, ‘src="__PUBLIC__/home/Js/‘) func = func.replace(‘url("../images/‘, ‘url("../Img/‘) func = func.replace(‘url(../images/‘, ‘url(../Img/‘) func = func.replace(‘href="css/‘, ‘href="__PUBLIC__/home/Css/‘) elif tr==‘tpweb‘: func = func.replace(‘src="images/‘, ‘src="__PUBLIC__/home/Web/Img/‘) func = func.replace(‘src="js/‘, ‘src="__PUBLIC__/home/Web/Js/‘) func = func.replace(‘url(../images/‘, ‘url(../Img/‘) func = func.replace(‘href="css/‘, ‘href="__PUBLIC__/home/Web/Css/‘) elif tr==‘formatcss‘: strinfo=re.compile(r‘([^}])\r\s+‘) strinfo2=re.compile(r‘([^}\n]{4,70})\n‘) strinfo3=re.compile(r‘([ ]{2,70})‘) strinfo4=re.compile(r‘(^[ ]{0,70})‘,re.M) strinfo5=re.compile(r‘\n[ \s]*\n‘) func=strinfo.sub(r‘\1‘,func) func=strinfo2.sub(r‘\1‘,func) func=strinfo3.sub(r‘‘,func) func=strinfo4.sub(r‘‘,func) func=strinfo5.sub(r‘\n‘,func) elif tr==‘tejg‘: func = func.replace(‘$GLOBALS[\‘db\‘]‘, ‘$db‘) func = func.replace(‘$GLOBALS[\‘ecs\‘]‘, ‘$ecs‘) func = func.replace(‘$GLOBALS[\‘_CFG\‘]‘, ‘$_CFG‘) func = func.replace(‘$GLOBALS[\‘_LANG\‘]‘, ‘$_LANG‘) func = func.replace(‘$GLOBALS[\‘smarty\‘]->‘, ‘$smarty->‘) elif tr==‘tezg‘: func = func.replace(‘$db->‘, ‘$GLOBALS[\‘db\‘]->‘) func = func.replace(‘$ecs->‘, ‘$GLOBALS[\‘ecs\‘]->‘) func = func.replace(‘$_CFG‘, ‘$GLOBALS[\‘_CFG\‘]‘) func = func.replace(‘$_LANG‘, ‘$GLOBALS[\‘_LANG\‘]‘) func = func.replace(‘$smarty->‘, ‘$GLOBALS[\‘smarty\‘]->‘) self.view.replace(edit, mark, func);
标签:
原文地址:http://www.cnblogs.com/flyskycode/p/5617419.html