---
title: "Dangling meta character '?' near index 0"
author: "J2EE大鸟"
date: "2012-12-19T20:20:48Z"
tags: []
categories: ["编程语言"]
slug: "dangling-meta-character-near-index-0"
draft: false
lastmod: "2012-12-19T20:20:48Z"
id: 1750623
url: "https://benworld.iteye.com/blog/1750623"
---

Problem

String str = "testing??"; 

str = str.replaceAll("?", ""); 

When you use the above pattern you get an exception as "Dangling meta character '?' near index 0" 

Solution 

String str = "testing??"; 

str = str.replaceAll("//?", ""); 

You can use the above solution when you are replacing * and + symbols 

String str = "testing??\*+"; 

str = str.replaceAll("//\*", ""); //"Dangling meta character '\*' near index 0"   
str = str.replaceAll("//+", ""); //"Dangling meta character '+' near index 0"

 

+、\*、|、/等符号在正则表达示中有相应的不同意义。  
一般来讲只需要加\[]、或是//即可

int i=s.split("\[?]").length;

或者

int i=s.split("//?").length;i);