File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Regular expressions ... Pls help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Regular expressions ... Pls help" Watch "Regular expressions ... Pls help" New topic

Regular expressions ... Pls help

Chirag Dua

Joined: Oct 08, 2005
Posts: 1
I have a string like this: cmCreateProductviewTag('<dynamic data>','<dynamic data>','<dynamic data>')

I want to remove single quotes and double quotes inside dynamic data strings ONLY
[ October 08, 2005: Message edited by: Michael Ernest ]
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

You may use split, to split the String, and replace the splitted parts separately, and handle the first and last element separately:

How to handle empty Strings, or lists of only one String ('<dynamic foo>') is left as an excercise...
Alan Moore
Ranch Hand

Joined: May 06, 2004
Posts: 262
There are some problems with Stefan's code, but the basic premise is correct; you can't do this replacement in a single stage using regexes. Here's another approach:I'm assuming the dynamic data is always surrounded by single quotes and angle brackets. If that isn't the case, you'll need some other way to identify it.
subject: Regular expressions ... Pls help
It's not a secret anymore!