This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
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


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Hey to all - a regex Q" Watch "Hey to all - a regex Q" New topic
Author

Hey to all - a regex Q

eliran mic
Greenhorn

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
Eliran
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.
 
 
subject: Hey to all - a regex Q