加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Textmate片段格式化字符串(正则表达式?)

发布时间:2020-12-14 05:36:16 所属栏目:百科 来源:网络整理
导读:我正在尝试创建一个可以改变它的textmate片段: HELLO WORLDbr /SAY ANYTHING 对此: hello world say anything 有帮助吗? 解决方法 在Allan Odgaard自己的帮助下: 片段 begin in: ${1:Hello} out: ${1/As+|s+Z|s*ns*|(brs*/?)|(.)/(?1: :L$2)
我正在尝试创建一个可以改变它的textmate片段:

HELLO WORLD<br />
SAY ANYTHING

对此:

hello world say anything

有帮助吗?

解决方法

在Allan Odgaard自己的帮助下:

片段

begin

  in:  ${1:Hello}

  out: ${1/As+|s+Z|s*ns*|(&;brs*/?&;)|(.)/(?1: :L$2)/ig}

end

测试

begin

  in:  THIS IS<br />
  WORKING<BR>
  VERY NICELY<br/>

  EVEN WITH MULTIPLE<BR />
  LINE BREAKS!

  out: this is working very nicely even with multiple line breaks!

end

正则表达式匹配说明

A      beginning of buffer
s+     followed by one or more whitespace

|       OR

s+     one or more whitespace
Z      followed by end of buffer

|       OR

s*     zero or more whitespace
n      followed by newline
s*     followed by zero or more whitespace

|       OR

(       Capture to 1
  <br   Literal `<br'
  s*   followed by zero or more whitespace
  /?   followed by one or zero literal `/'
  >     followed by literal `>'
)       End capture

|       OR

(       Capture to 2
  .     Any character
)       End capture

正则表达式替换说明

注意:条件替换是TextMate独有的

(?1:    IF Capture 1 is found
        Insert space (' ')
  :     ELSE
  L$2  Insert lowercase(Capture 2)
)       ENDIF

正则表达式修饰符解释

i       case insensitive
g       global match/replace

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读