使用正则表达式匹配除=以外的任何字符

编程入门 行业动态 更新时间:2024-10-27 06:31:37
本文介绍了使用正则表达式匹配除=以外的任何字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试编写一个String验证来匹配任何字符(常规,数字和特殊),除了=。

I am trying to write a String validation to match any character (regular, digit and special) except =.

这是我写的 -

String patternString = "[[^=][\\w\\s\\W]]*"; Pattern p = Patternpile(patternString); Matcher m = p.matcher(str); if(m.matches()) System.out.println("matches"); else System.out.println("does not");

但是,它与输入字符串2009-09 / 09 12:23:12.5 =匹配模式。

But, it matches the input string "2009-09/09 12:23:12.5=" with the pattern.

如何从模式字符串中排除=(或任何其他字符)?

How can I exclude = (or any other character, for that matter) from the pattern string?

推荐答案

如果唯一禁止的字符是等号,那么 [^ =] * 之类的东西应该有用。

If the only prohibited character is the equals sign, something like [^=]* should work.

[^ ...] 是一个否定的字符类;它匹配单个字符,除了方括号中的列表之外的任何字符。 * 重复表达式零次或多次。

[^...] is a negated character class; it matches a single character which is any character except one from the list between the square brackets. * repeats the expression zero or more times.

更多推荐

使用正则表达式匹配除=以外的任何字符

本文发布于:2023-11-06 16:11:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1564172.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符   正则表达式

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!