• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hey to all - a regex Q

 
eliran mic
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm programming for university project a scientific calculator
I'm trying to find expression in the middle of the line input with square brackets
The regax looks like this
"[([)][*]+[(])]"

But when I enter the command
int startIndex = match.regionStart ();
int endIndex = match.regionEnd ();

I get the index of the beginning of the string and the end instead where brackets Location

(Input can show that 3 + [4 * 5] or more complex expression)

For input 3 + [4 * 5]
startIndex will be 0
endIndex will be 11

What am I doing wrong???

Thanks in advance
Eliran
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The characters []*+ are special characters. You need to escape them.
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the JavaRanch.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic