• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Parsing a string with non-whitespace leading and trailing characters

 
Salman Ahmed
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using J2SE 1.5, and am wondering what's the best way to parse a string from a line that has the following format:

[some-text-here]

I need to remove the leading "[" and trailing "]" characters and get just the "some-text-here" string.

Thanks.
 
Steve Luke
Bartender
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A simple regex for this would be:


You could run it like this:


It doesn't help with complex matching like brackets inside brackets... but it is a start.
 
Salman Ahmed
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steve,

this is precisely what I was looking for - thanks!

Regards,


Salman Ahmed
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic