Skip to main content
 首页 » 编程设计

regex之如何在Android Studio logcat中过滤多个单词

2024年11月01日14bhlsheji

我只想在 logcat 中看到几个字。换句话说,只是一个给定的标签。我尝试启用正则表达式并输入 [Encoder|Decoder]作为过滤器,但它不起作用。

请您参考如下方法:

您应该使用分组结构:

(Encoder|Decoder) 

其实你可以用
Encoder|Decoder 

如果您使用 [Encoder|Decoder] ,创建匹配任何单个字符的字符类 E , n , c ... | , D ... 或 r .

Character Classes or Character Sets :

With a "character class", also called "character set", you can tell the regex engine to match only one out of several characters. Simply place the characters you want to match between square brackets. If you want to match an a or an e, use [ae].



另一个必读当然是 Alternation with The Vertical Bar or Pipe Symbol :

If you want to search for the literal text cat or dog, separate both options with a vertical bar or pipe symbol: cat|dog. If you want more options, simply expand the list: cat|dog|mouse|fish.



使用时 (...) 您告诉正则表达式引擎对字符/子模式序列进行分组(使用捕获序列,子匹配存储在内存缓冲区中,您可以通过反向引用访问它们,而对于非捕获 (?:...),您只能对子模式进行分组):

By placing part of a regular expression inside round brackets or parentheses, you can group that part of the regular expression together. This allows you to apply a quantifier to the entire group or to restrict alternation to part of the regex.