?
Solved

Regexpression really stuck ---

Posted on 2005-03-07
3
Medium Priority
?
224 Views
Last Modified: 2010-03-31
I have a string literal like this


String s = "function(ab,'ac',ad,'gr')";

Now I want to run a reg expression so that I can only get ab and ad (i.e. only the strings that are enclosed in the single quotes). I donot want to get values which are wrapped by single quote.

Thanx in advance ...

EK
0
Comment
Question by:rahulkothari
  • 2
3 Comments
 
LVL 6

Accepted Solution

by:
durgaprasad_j earned 1500 total points
ID: 13483938
hi
try this

Regular expression for matching the whole string is  ".*\\((.*),\'.*\',(.*),\'.*\'\\)"
Reg Expression for breaking the string is "[(|,]"
you can get ab and ad as as[1] and as[3]
public class RegEXPTest
{
      public static void main(String args[])
      {
            String s = "function(ab,'ac',ad,'gr')";
            System.out.println(s.matches(".*\\((.*),\'.*\',(.*),\'.*\'\\)"));
            String as[]=s.split("[(|,]");
            System.out.println(as[1] + " "+ as[3]);
      }
}
Hope this helps
0
 

Author Comment

by:rahulkothari
ID: 13487800
thanx even tought it was not accurate it gave me enough clues ... that was not of work ... beleive me for this one ...

RK
0
 
LVL 6

Expert Comment

by:durgaprasad_j
ID: 13488008
ok i believe you.
Thanks for accepting  
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Don’ts and Dos are two important end products of software testing basics that a tester needs to regard. This article attempts to explain the principles of both.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses
Course of the Month9 days, 11 hours left to enroll

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question