regexp中是否有(!)运算符? [英] Is there a not (!) operator in regexp?
本文介绍了regexp中是否有(!)运算符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要删除给定字符串中的所有字符,除了应该留下的几个字符。如何使用regexp?
I need to remove all characters from the given string except for several which should left. How to do that with regexp?
简单测试:不应删除字符[1,a,*],其他所有字符串应来自字符串asdf123 **。
Simple test: characters[1, a, *] shouldn't be removed, all other should from string "asdf123**".
推荐答案
在集合中有:^。
你应该能够做类似的事情:
You should be able to do something like:
text = text.replaceAll("[^1a*]", "");
完整样本:
public class Test
{
public static void main(String[] args)
{
String input = "asdf123**";
String output = input.replaceAll("[^1a*]", "");
System.out.println(output); // Prints a1**
}
}
这篇关于regexp中是否有(!)运算符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文