字符类减法,从Java语法转换为RegexBuddy [英] Character class subtraction, converting from Java syntax to RegexBuddy

查看:84
本文介绍了字符类减法,从Java语法转换为RegexBuddy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java使用哪个正则表达式引擎?

Which regular expression engine does Java uses?

如果我使用RegexBuddy之类的工具

In a tool like RegexBuddy if I use

[a-z&&[^bc]]

Java中的表达式很好,但是在RegexBuddy中尚未理解.

that expression in Java is good but in RegexBuddy it has not been understood.

实际上它报告:

匹配出现在其中的单个字符 [a-z&&[^bc]

Match a single character present in the list below [a-z&&[^bc]

  • az之间的字符: a-z
  • 字符&[^bc之一: &&[^bc
  • 从字面上匹配字符]: ]
  • A character in the range between a and z : a-z
  • One of the characters &[^bc : &&[^bc
  • Match the character ] literally : ]

但我想匹配az之间的字符,该字符与不是bc

but i want to match a character between a and z intersected with a character that is not b or c

推荐答案

像大多数正则表达式一样,

Like most regex flavors, java.util.regex.Pattern has its own specific features with syntax that may not be fully compatible with others; this includes character class union, intersection and subtraction:

  • [a-d[m-p]]:ad,或mp:[a-dm-p] (联合)
  • [a-z&&[def]]:def (交叉点)
  • [a-z&&[^bc]]:az,除了bc:[ad-z] (减法)
  • [a-d[m-p]] : a through d, or m through p: [a-dm-p] (union)
  • [a-z&&[def]] : d, e, or f (intersection)
  • [a-z&&[^bc]] : a through z, except for b and c: [ad-z] (subtraction)

Java正则表达式最重要的"caveat"是matches尝试将模式与整个字符串匹配.这对于大多数引擎而言都是非典型的,有时可能会引起混乱.

The most important "caveat" of Java regex is that matches attempts to match a pattern against the whole string. This is atypical of most engines, and can be a source of confusion at times.

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆