RegEx如何正确使用OR管道

时间:2022-09-11 20:55:10

I need to know how to properly use "OR" when it comes to individual characters and whole phrases... For example I have code that is checking for any number of characters OR words that are found in an array...

我需要知道如何在单个字符和整个短语中正确使用“OR”...例如,我有代码检查任何数量的字符或在数组中找到的单词...

I want to check for some unicode characters and also some html lines of code.

我想检查一些unicode字符以及一些html代码行。

I'm currently just checking for the characters using this:

我目前正在使用这个来检查字符:

([\u200b\u200c\u200d\0\1\2\3\4\5\6\7]*)

(the backslashes are representing the unicode characters u+200b - u+200d and the special characters in my software \0-\7 (They are all individual characters), these are valid escape sequences in Objective-C.)

(反斜杠表示unicode字符u + 200b - u + 200d和我软件中的特殊字符\ 0- \ 7(它们都是单个字符),这些是Objective-C中的有效转义序列。)

Now what if I wanted to check for these characters AND check for phrases like <b> or <font color="#FF0000">

现在如果我想检查这些字符并检查之类的短语

I found stuff while doing research that said to use pipelines | but I'm not sure if I put them only in-between the words or also in-between the individual characters and I'm not sure if I put quotes around the words or what not... I need help before I screw this up badly haha!

我在做研究时发现了一些据说使用管道的东西但是我不确定我是将它们放在两个词之间还是在各个角色之间,我不确定我是否在这些词语周围加上引号或者我不需要帮助......在我搞这个之前我需要帮助哈哈!

(p.s., not sure if it will be any different but I'm also doing it for this:

(p.s.,不确定它是否会有所不同,但我也是这样做的:

([^\u200b\u200c\u200d\0\1\2\3\4\5\6\7])

1 个解决方案

#1


1  

it's be someting like

这有点像

/([^....]|\<b\/\>|\<font color .... \>)/

though, the usual caveats about regexes and html apply here.

虽然,关于正则表达式和html的常见警告适用于此处。

As for the confusion about where to put the |, consider this this hackneyed example: You want to find the word color, but also want to accommodate the british spelling, colour:

至于关于在哪里放置|的困惑,请考虑这个这个陈腐的例子:你想找到颜色这个词,还想要适应英国的拼写,颜色:

/(color|colour)/
/(colou?r)/
/(colo(r|ur))/

are all basically equivalent.

基本上都是等价的。

#1


1  

it's be someting like

这有点像

/([^....]|\<b\/\>|\<font color .... \>)/

though, the usual caveats about regexes and html apply here.

虽然,关于正则表达式和html的常见警告适用于此处。

As for the confusion about where to put the |, consider this this hackneyed example: You want to find the word color, but also want to accommodate the british spelling, colour:

至于关于在哪里放置|的困惑,请考虑这个这个陈腐的例子:你想找到颜色这个词,还想要适应英国的拼写,颜色:

/(color|colour)/
/(colou?r)/
/(colo(r|ur))/

are all basically equivalent.

基本上都是等价的。