如何解析文本区域中的花式文本

huangapple go评论60阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年2月14日 20:04:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/75447592.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定