Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dangling meta character '+' 1

Status
Not open for further replies.

fmaurer

Technical User
Joined
May 15, 2007
Messages
11
Location
PL
Hi,

what I am trying to do i to split an expression like 1+2+3 and use + as delimiter. The problem is that I cannot do it neither using
Code:
String s = new String("1+2+3");
s.split("+");
nor
Code:
Scanner s = new Scanner("1+2+3");
s.useDelimiter("+");
What I've read is that + cannot be used as a regular expression but maybe there is some way to do it?
Regards,
Martin
 
I'd try escaping it: "\+" in the regex.

Cheers,
Dian
 
Unfortunately I've already tried it
"Invalid escape sequence (valid ones are \b \t \n \f \r \" \' \\ )
 
+ is not a metacharacter in Java-Source, but \ is.
\n, \t have special meanings.

So you mask the plus for regular expressions with a \, but you have then to mask the \ with another one, which will lead to "\\+".

Might produce headaches, when getting more complicated. :)

don't visit my homepage:
 
It works :)
Thank you stefan. Seems that I have to read much more about reg. expressions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top