File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Hey to all - a regex Q Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Hey to all - a regex Q" Watch "Hey to all - a regex Q" New topic

Hey to all - a regex Q

eliran mic

Joined: Apr 03, 2011
Posts: 1
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
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

The characters []*+ are special characters. You need to escape them.

"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

And welcome to the JavaRanch.
I agree. Here's the link:
subject: Hey to all - a regex Q
It's not a secret anymore!