• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

java regular expression giving stack overflow ?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using following code to find and remove all the comments in java source code file


This will run for few times but then throws following exception..



Please help by pointing me what's wrong with Reg Exp I am using.
 
Ranch Hand
Posts: 492
Firefox Browser VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should try removing the simple comments first ('//') then after you know that regex works, create a regex to match the block comments, then after that works combine them.

Hunter
 
Ranch Hand
Posts: 781
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

gpmax bond wrote:
Please help by pointing me what's wrong with Reg Exp I am using.


You need to make the "*" following the )) possessive otherwise you have the potential for massive backtracking.

Making this possessive will solve the stack overflow problem but I don't know if the regex will then perform as desired; you must test that.

You also seem to have a number of redundant non-capturing groups. I think you can reduced the regex to
 
reply
    Bookmark Topic Watch Topic
  • New Topic