英文:
How to Parse the Fancy Text From Text Area
问题
我在复制粘贴花体文本和表情符号到文本框时遇到了一些问题,
类似于 😋 和 🅵🅰🅽🅲🆈 🆃🅴🆇🆃 🅶🅴🅽🅴🆁🅰🆃🅾🆁
我已经用以下代码移除了表情符号:
e.content.replace(/([\u2700-\u27BF]|[\uE000-\uF8FF]|\uD83C[\uDC00-\uDFFF]|\uD83D[\uDC00-\uDFFF]|[\u2011-\u26FF]|\uD83E[\uDD10-\uDDFF])/g, ''')
同时我也想移除特殊字体和花体文本,但是找不到方法。
是否有类似于处理表情符号的方法来解决这个问题?
英文:
I am facing some issues when copy paste the fancy texts and emojis in a textarea,
Like 😋 and 🅵🅰🅽🅲🆈 🆃🅴🆇🆃 🅶🅴🅽🅴🆁🅰🆃🅾🆁
I have removed the emojis with following code:
e.content.replace(/([\u2700-\u27BF]|[\uE000-\uF8FF]|\uD83C[\uDC00-\uDFFF]|\uD83D[\uDC00-\uDFFF]|[\u2011-\u26FF]|\uD83E[\uDD10-\uDDFF])/g, '')
Also wanted to remove the special fonts and fancy texts as well, but not finding a way.
is there any way around for this, like i did for the emojis.
答案1
得分: 1
ECMAScript 6的正则表达式解决方案用于匹配带方框字母的是
.replace(/[\u{1F170}-\u{1F189}]+/gu, ''')
要同时匹配数学和标点符号,您可以使用以下符合ECMAScript 2018+的正则表达式:
.replace(/[\u{1F170}-\u{1F189}\p{P}\p{S}]+/gu, ''')
需要使用u
标志使\u{XXXX}
表示法和\p{X}
Unicode类别生效。
模式详情
\u{1F170}-\u{1F189}
- 方框字母\p{P}
- 标点符号\p{S}
- 数学符号。
英文:
ECMAScript 6 regex solution to match the squared letters is
.replace(/[\u{1F170}-\u{1F189}]+/gu, '')
To also match math and punctuation symbols, you can use the following ECMAScript 2018+ compliant regex:
.replace(/[\u{1F170}-\u{1F189}\p{P}\p{S}]+/gu, '')
The u
flag is required to make \u{XXXX}
notation and \p{X}
Unicode categories work.
Pattern details
\u{1F170}-\u{1F189}
- squared letters\p{P}
- punctuation proper\p{S}
- math symbols.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论