Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: How to remove the regular expression from a string ?

  1. #1
    Junior Member
    Join Date
    Jul 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to remove the regular expression from a string ?

    Hi,
    I have a string which is dynamic.
    The string will be like

    "<li><p align="&quot;left&quot;">Testing data</p></li>".
    "<li><div align="&quot;left&quot;">Testing data</div></li>".
    "<li><div align="&quot;left&quot;" valign="center"><p align="left">Testing data</p></div></li>".

    Here I have to remove the <div> and <p>tags present inside the <li> </li> but remember the tags are dynamic. It can be anything.

    So, the out put will be as "<li>Testing data</li>".


    Please help.
    Last edited by srimanta; July 20th, 2011 at 10:06 AM.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,441
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 544 Posts

    Default Re: How to remove the regular expression from a string ?

    What did the API tell you?

    String (Java Platform SE 6)
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Jul 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to remove the regular expression from a string ?

    But the data to replace is not static data. I am not familiar with the reg exp. So, i need that particular regexp which I need to replace.

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,441
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 544 Posts

    Default Re: How to remove the regular expression from a string ?

    Quote Originally Posted by srimanta View Post
    But the data to replace is not static data. I am not familiar with the reg exp. So, i need that particular regexp which I need to replace.
    Again, sounds like you need to consult the API, or at least google. We can't just do your work for you.

    Read through this, try something out, and if you're still stuck, post an SSCCE and we'll go from there: Pattern (Java Platform SE 6)
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,330
    Thanks
    181
    Thanked 828 Times in 771 Posts
    Blog Entries
    5

    Default Re: How to remove the regular expression from a string ?

    Also recommend reading Lesson: Regular Expressions (The Java™ Tutorials > Essential Classes)
    While I don't completely understand your requirements and what you mean by 'tags are dynamic', break your problem down. A single regular expression may do the trick, but you could probably also use several regular expressions together to accomplish your goals

  6. #6
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 287 Times in 225 Posts
    Blog Entries
    4

    Default Re: How to remove the regular expression from a string ?

    I suggest you read - http://www.javaprogrammingforums.com...explained.html

    There are other ways to do this though.

    I suggest you write a small program to work on 1 static String.
    Test different methods, get an idea of the logic involved and then expand on it..
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

Similar Threads

  1. Regular Expression pattern - complex pattern syntax
    By SmartAndy in forum Algorithms & Recursion
    Replies: 3
    Last Post: June 7th, 2011, 04:40 AM
  2. Regular Expression help
    By medoos in forum Java SE APIs
    Replies: 0
    Last Post: March 19th, 2011, 07:23 PM
  3. Simple Hashsets and regular expression problem !
    By burningflower in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 10th, 2011, 12:43 PM
  4. Using Regular Expression (regex) in Java Programming
    By lordelf007 in forum What's Wrong With My Code?
    Replies: 8
    Last Post: May 14th, 2010, 10:29 AM
  5. How to remove the in-between spaces in a String? Please help.
    By marksquall in forum Java Theory & Questions
    Replies: 2
    Last Post: February 4th, 2010, 03:19 PM