如何在 Live Templates 中使用 regularExpression 函数?
How to use regularExpression function in Live Templates?
- 我正在尝试使用正则表达式从剪贴板插入值。怎么做?
- 是否可以使用正则表达式删除带有属性的 svg 标签?
我试着写 regularExpression(SVG, width="(\d+)px", )
和这个的变体。
例如
我的剪贴板中有这个
<svg width="32px" height="32px" viewBox="0 0 32 32" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g transform="translate(-932.000000, -4274.000000)">
<g transform="translate(0.000000, 4184.000000)">
<g transform="translate(932.000000, 90.000000)">
<rect fill="#3C5494" x="0" y="0" width="32" height="32" rx="16"></rect>
<path d="M17.1973392,16.7117794 L19.5654279,16.7117794 L19.9199468,13.8590668 L17.1973392,13.8590668 L17.1973392,12.0421097 C17.1973392,11.2181543 17.4178625,10.6566668 18.5566829,10.6566668 L20,10.6559859 L20,8.11206559 C19.7488603,8.07744655 18.887255,8 17.8848071,8 C15.7919823,8 14.3592018,9.32549911 14.3592018,11.759728 L14.3592018,13.8590668 L12,13.8590668 L12,16.7117794 L14.3592018,16.7117794 L14.3592018,24 L17.1973392,24 L17.1973392,16.7117794 Z" fill="#FFFFFE"></path>
</g>
</g>
</g>
</g>
</svg>
我用这个模板
/* eslint-disable max-len */
import React from 'react'
import Icon from './Icon'
const $NAME$ = ({ width, height }) => (
<Icon
width={width}
height={height}
viewBox='0 0 $width$ $height$'
>
$SVG$$END$
</Icon>
)
export default $NAME$
我正在尝试从 svg 属性中插入 $width$ 和 $height$
我除了 viewBox 是 '0 0 32 32'
,但我得到 '0 0 '
regularExpression(String, Pattern, Replacement)
Live Template 函数是 运行 以下方式:匹配 Pattern
的 String
中的所有出现都被第三个参数替换,结果字符串是返回(参见 https://github.com/JetBrains/intellij-community/blob/master/platform/lang-impl/src/com/intellij/codeInsight/template/macro/RegExMacro.java 中的函数实现)。因此,regularExpression(SVG, width="(\d+)px", )
的结果是您的剪贴板内容 width="32px"
替换为 32
- 我正在尝试使用正则表达式从剪贴板插入值。怎么做?
- 是否可以使用正则表达式删除带有属性的 svg 标签?
我试着写 regularExpression(SVG, width="(\d+)px", )
和这个的变体。
例如
我的剪贴板中有这个
<svg width="32px" height="32px" viewBox="0 0 32 32" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g transform="translate(-932.000000, -4274.000000)">
<g transform="translate(0.000000, 4184.000000)">
<g transform="translate(932.000000, 90.000000)">
<rect fill="#3C5494" x="0" y="0" width="32" height="32" rx="16"></rect>
<path d="M17.1973392,16.7117794 L19.5654279,16.7117794 L19.9199468,13.8590668 L17.1973392,13.8590668 L17.1973392,12.0421097 C17.1973392,11.2181543 17.4178625,10.6566668 18.5566829,10.6566668 L20,10.6559859 L20,8.11206559 C19.7488603,8.07744655 18.887255,8 17.8848071,8 C15.7919823,8 14.3592018,9.32549911 14.3592018,11.759728 L14.3592018,13.8590668 L12,13.8590668 L12,16.7117794 L14.3592018,16.7117794 L14.3592018,24 L17.1973392,24 L17.1973392,16.7117794 Z" fill="#FFFFFE"></path>
</g>
</g>
</g>
</g>
</svg>
我用这个模板
/* eslint-disable max-len */
import React from 'react'
import Icon from './Icon'
const $NAME$ = ({ width, height }) => (
<Icon
width={width}
height={height}
viewBox='0 0 $width$ $height$'
>
$SVG$$END$
</Icon>
)
export default $NAME$
我正在尝试从 svg 属性中插入 $width$ 和 $height$
我除了 viewBox 是 '0 0 32 32'
,但我得到 '0 0 '
regularExpression(String, Pattern, Replacement)
Live Template 函数是 运行 以下方式:匹配 Pattern
的 String
中的所有出现都被第三个参数替换,结果字符串是返回(参见 https://github.com/JetBrains/intellij-community/blob/master/platform/lang-impl/src/com/intellij/codeInsight/template/macro/RegExMacro.java 中的函数实现)。因此,regularExpression(SVG, width="(\d+)px", )
的结果是您的剪贴板内容 width="32px"
替换为 32