Exception in thread "main" java.util.regex.PatternSyntaxException: Unclosed character class near index 0 [ ^

出现此错误应该是字符转义出现问题:

System.out.println(str.replaceAll("[", "22"));
解决方案:在[之前加上\\
System.out.println(str.replaceAll("\\[", "22"));

随机推荐

  1. WEB-INF& 绝对路径vs相对路径

    在struts2里面用XXXInput方法和springmvc里面用GET模式进入添加或者登陆输入页面,有时候会在方法里面做一下准备,比如动态读入部门信息放在select中,或者在model中加入一个 ...

  2. Map的遍历

    @Test public void test() { Map<String,String> usersmap = new HashMap<>(); usersmap.put(& ...

  3. Java 获取APK安装程序的包名

     Java 获取APK安装程序的包名核心的两个类:  ResPackage ApkDecoder  package com.temobi.util; import java.io.File; impo ...

  4. Note_Master-Detail Application(iOS template)_02_YJYAppDelegate.m

    //YJYAppDelegate.m #import "YJYAppDelegate.h" #import "YJYMasterViewController.h" ...

  5. Sql Server REPLACE函数的使用;SQL中 patindex函数的用法

    Sql Server REPLACE函数的使用 REPLACE用第三个表达式替换第一个字符串表达式中出现的所有第二个给定字符串表达式. 语法REPLACE ( ''string_replace1'' ...

  6. Android 编译Settings、Mms等模块,并Push到手机中安装失败

    问题描述:在编译完Settings等相关模块后,并push到手机中安装失败(在手机中无法找到该应用),但是使用adb shell命令进入到手机中在System/app或者System/priv-app ...

  7. BZOJ 3997 组合数学

    好厉害. 注意到到了(i,j)就一定到不了(i-1,j+1),那么可以dp啦.dp[i][j]表示(i,j)右上角都清了的方案数. #include<iostream> #include& ...

  8. BZOJ 3687 简单题

    bitset维护某个和是否存在. bit<<x:所有子集的和+x. #include<iostream> #include<cstdio> #include< ...

  9. js实现图片预显示

    html页面代码 <div id="localImag" style="display:none"><img  id="previe ...

  10. 【Tsinghua OJ】祖玛(Zuma)问题

    描述 祖玛是一款曾经风靡全球的游戏,其玩法是:在一条轨道上初始排列着若干个彩色珠子,其中任意三个相邻的珠子不会完全同色.此后,你可以发射珠子到轨 道上并加入原有序列中.一旦有三个或更多同色的珠子变成相 ...