简体   繁体   English

正则表达式尝试| 匹配表情符号和图案

[英]Regex Attempt | Matching Emojis and Pattern

So I've been trying to match this type of pattern for a while. 所以一段时间以来,我一直在尝试匹配这种类型的模式。 I'm using RegExr to test my things out, I ended up with this: 我使用RegExr来测试我的东西,最终得到了这个:

(\[★+\] [A-Za-z0-9]\s?-?[A-Za-z0-9] ?\w+?\s?[A-Za-z0-9]\s?\w+ ?\[?[A-Za-z0-9]\w+\]?[A-Za-z0-9]\s?\w+ ?\[?[A-Za-z0-9]-?\w+\])

This one hardly matched almost everything, as seen here . 这其中很难匹配几乎所有的东西,因为看到这里 I'm still new to using RegEx but i figured out one the experts out here can help me. 我仍然不熟悉RegEx,但我发现这里的专家可以为我提供帮助。

The Regex need to match every entry, separated. 正则表达式需要匹配每个分开的条目。 In attempt to form a database. 试图建立数据库。

Try this one : \\[(★|🎄|🍰)+\\](\\s[❤\\w-]+\\s?)+\\[[\\w-]+\\] 试试这个: \\[(★|🎄|🍰)+\\](\\s[❤\\w-]+\\s?)+\\[[\\w-]+\\]

\\[(★|🎄|🍰)+\\] matches [★] [🎄] [🍰] with as many star/tree/cake as possible \\[(★|🎄|🍰)+\\]与[★] [🎄] [🍰]匹配的星/树/蛋糕越多越好

(\\s[❤\\w-]+\\s?)+ matches a space character followed by ❤ or A-Za-z0-9_ or - followed by a potential space (0 or 1), and all that as many time as possible (\\s[❤\\w-]+\\s?)+匹配一个空格字符,后跟❤或A-Za-z0-9_或-后面跟一个潜在的空格(0或1),以及所有与可能

\\[[\\w-]+\\] matches [ followed by as many as possible A-Za-z0-9_ or - followed by ] \\[[\\w-]+\\]匹配[,后跟尽可能多的A-Za-z0-9_或-后跟]

Demo 演示

It's hard to give you a clean regexp since I don't know rules; 因为我不知道规则,所以很难给您一个干净的正则表达式。 by example: 例如:

  • do you need to select only stars or emoticons "cake part", "tree" and anything else ? 您是否只需要选择星星或表情符号“蛋糕部分”,“树”以及其他内容?
  • does a line always ends with ascii text between [] ? 一行总是以[]之间的ascii文本结尾吗?

I can give you a "large" regexp but there may be side effects, with more details we can make better regex 我可以给你一个“大”的正则表达式,但可能会有副作用,更多的细节我们可以制作更好的正则表达式

^\\[(.+)\\] (.*?) \\[([\\w\\-]+)\\]$

https://regex101.com/r/eU7vis/1 https://regex101.com/r/eU7vis/1

^\\[(.+)\\] Gets and ensures the first part (emoticon simple or multiple or any character between [] ). ^\\[(.+)\\]获取并确保第一部分(表情符号简单或多个或[]之间的任何字符)。 We could limit authorized chars if you have constraints. 如果您有限制,我们可以限制授权字符。

(.*?) Gets the minimum of characters (any character) as far as we are not matching next part (.*?)获取不匹配下一部分的最少字符(任何字符)

\\[[\\w\\-]+\\]$ Gets and ensures string ends with text between [] . \\[[\\w\\-]+\\]$获取并确保字符串以[]之间的文本结尾。 Authorized chars in this part are alphabet letters (lower and upper), digits, underscore and hyphen. 本部分中授权的字符是字母(上下),数字,下划线和连字符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM