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 SkipVought 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
May 15, 2007
11
0
0
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
 
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