473,383 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Replace "+" with "\\+"

I want to replace + sign with 2 blackslash and 1 + sign (\\+)...
when I use the replaceAll()...
It throws a 500 status error like
"java.util.regex.PatternSyntaxException: Dangling meta character '+' near index 0"

wht s the solution or how can I replace ????
Jan 10 '08 #1
8 3028
r035198x
13,262 8TB
I want to replace + sign with 2 blackslash and 1 + sign (\\+)...
when I use the replaceAll()...
It throws a 500 status error like
"java.util.regex.PatternSyntaxException: Dangling meta character '+' near index 0"

wht s the solution or how can I replace ????
Bit of a nasty one that

Expand|Select|Wrap|Line Numbers
  1. replaceAll("\\+", "\\\\\\\\+")
Jan 10 '08 #2
dmjpro
2,476 2GB
Bit of a nasty one that

Expand|Select|Wrap|Line Numbers
  1. replaceAll("\\+", "\\\\\\\\+")
How does it work can you explain?

Debasis Jana
Jan 10 '08 #3
r035198x
13,262 8TB
How does it work can you explain?

Debasis Jana
Remember that + is a special character and \ is a special-special character.
To match one \ you need four \
Jan 10 '08 #4
BigDaddyLH
1,216 Expert 1GB
I'm not a big fan of regex (They're why I run screaming from PERL, but then isn't that known as a "write once" language because you don't ever want to read your own code?).

Anyhowdy, if you are just replacing text, there is no need to use String's replaceAll method which drags regex patterns into the fray. Use String's replace method which simply replaces all occurrences of the first string with the second.

Expand|Select|Wrap|Line Numbers
  1. result = s.replace("+", "\\\\+");
(You still need to escape \ as you always do in any string, of course.)

String.replace API
Jan 10 '08 #5
r035198x
13,262 8TB
I'm not a big fan of regex (They're why I run screaming from PERL, but then isn't that known as a "write once" language because you don't ever want to read your own code?).

Anyhowdy, if you are just replacing text, there is no need to use String's replaceAll method which drags regex patterns into the fray. Use String's replace method which simply replaces all occurrences of the first string with the second.

Expand|Select|Wrap|Line Numbers
  1. result = s.replace("+", "\\\\+");
(You still need to escape \ as you always do in any string, of course.)

String.replace API
Why do all mathematicians seem to have some sort of history with Perl ...
Jan 11 '08 #6
BigDaddyLH
1,216 Expert 1GB
Why do all mathematicians seem to have some sort of history with Perl ...
Maybe it's being relegated to linux/UNIX machines where it's more likely you'll bump into it. That's what happened to me.
Jan 11 '08 #7
JosAH
11,448 Expert 8TB
Maybe it's being relegated to linux/UNIX machines where it's more likely you'll bump into it. That's what happened to me.
Until now I managed to stay as far away as possible from Larry Wall's miscarriage.
I only trust that Perl as far as i can throw a rock at it.

kind regards,

Jos
Jan 11 '08 #8
BigDaddyLH
1,216 Expert 1GB
Until now I managed to stay as far away as possible from Larry Wall's miscarriage.
I only trust that Perl as far as i can throw a rock at it.

kind regards,

Jos
I'm scared to look at the Perl forum to see what they're writing about us!
Jan 11 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Luke Dalessandro | last post by:
I have an application where there is a primary XML data file. I'll use the following as an example: <data> <item id="a"> <name>A</name> <price>$10</price> </item> <item id="b">...
6
by: vigi98 | last post by:
Hello all, Can someone confirme that this: var strURLpiece = "UK & Ireland"; strURLpiece.replace("&", "%26"); replaces all occurrence of the character & by %26 in strURLpiece, ie that...
3
by: asd987 | last post by:
Hi, Can anyone tell me if "replace" is supported by Access 97? I use the Dutch version and get the errormessage "sub or function not supported". Or is the Professional Edition needed? Thanks.
2
by: ad | last post by:
Hello, if I try this ((StringBuilder)sb).Replace("a", "aa"); I get OutOfMemoryException raised if sb contains at least one "a"... It seems like StringBuilder 'seeker' doesn't move to the end...
6
by: Marty | last post by:
Hi, I would like to replace "\r\n" by "_" within a specific string. I tried : strMyString.Replace('\r', '_'); strMyString.Replace('\n', '_'); or...
6
by: Dean Slindee | last post by:
Private NameLastFirst as object = "Public, John Q." NameLastFirst = Replace(LastName, "'", "''") If NameLastFirst contains "Public, John Q." before the above Replace, it will contain "Public"...
0
by: Rave | last post by:
This is a long shot, but I thought I'd try it. I am currently using excel as an inventory tool. I currently have a hand-held scanner plugged into a laptop for reading barcodes. Using the "Find and...
2
by: John Nagle | last post by:
I'm trying to clean up a bad ASCII string, one read from a web page that is supposedly in the ASCII character set but has some characters above 127. And I get this: File...
1
by: jx2 | last post by:
lets say i've got a str="john michael luise+marry" i need to replace all ocurrance of name with name+surname eg str2= "johnBrown michealBrown luiseBrown+marryBrown" i gues i need something like...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.