?
Solved

Regexpression really stuck ---

Posted on 2005-03-07
3
Medium Priority
?
218 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month9 days, 9 hours left to enroll

762 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