Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / January 2006

Tip: Looking for answers? Try searching our database.

regular expressions

Thread view: 
Brandon McCombs - 09 Jan 2006 01:34 GMT
hello,

The java doc on Sun's site is useless for figuring out how to do a
split() on a string and to split on either a ( or a ).  I noticed that I
have to use \p{Punct} but the page says nothing on how to do that. Can
anyone help me? I've created a Pattern object and think I have to
compile the pattern but I have no damn clue what the pattern is supposed
to be with the stupid \p argument that I have to use just to split on a
( or ). I don't know why they can't be used as commas because with
commas I don't have to do anything special to make the split work.

thanks
hiwa - 09 Jan 2006 02:17 GMT
( and ) should be escaped as \\( and \\)
Read the API documentation of java.util.regex.Pattern class.
Brandon McCombs - 09 Jan 2006 03:09 GMT
> ( and ) should be escaped as \\( and \\)
> Read the API documentation of java.util.regex.Pattern class.

The proper escaping was what I needed. I found it hard to believe I had
to go to the trouble of making a pattern object.  I was only escaping
with 1 backslash when I had tried it previously.
thanks
hiwa - 09 Jan 2006 03:51 GMT
In a Java string, you need to write two backslashes.
Roedy Green - 09 Jan 2006 04:33 GMT
>( or ). I don't know why they can't be used as commas because with
>commas I don't have to do anything special to make the split work.

See http://mindprod.com/jgloss/regex.html
You want a pattern that is either ( or ).

You have likely seen pattern of the form [01]
to allow either 0 or 1.

Do the same thing with ( and )

namely [()]

However, () have magic meaning in Regexes, so you quote them to tell
Java you mean them literally, not as command characters.

namely "[\(\)]"

The problem with that is Java also uses \ for quoting in strings. So
to let Java know you meant those \ literally you must double them.

namely "[\\(\\)]"

That's your pattern for the split.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

ricky.clarkson@gmail.com - 13 Jan 2006 02:08 GMT
Roedy,

I refer people in another medium to your regex page when we get
questions where the answer is a double-escape, with the following text:

"http://mindprod.com/jgloss/regex.html#VARIANTS - see the first text
under the Function heading."

Could you possibly make that part less table-based, or provide another
page just for the 'double escape' part?  Something I can give a less
vague link to.

Regards.
Roedy Green - 13 Jan 2006 03:33 GMT
On 12 Jan 2006 18:08:06 -0800, "ricky.clarkson@gmail.com"
<ricky.clarkson@gmail.com> wrote, quoted or indirectly quoted someone
who said :

>Could you possibly make that part less table-based, or provide another
>page just for the 'double escape' part?  Something I can give a less
>vague link to.

done.  Should show up on the website in a few minutes.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

ricky.clarkson@gmail.com - 13 Jan 2006 10:50 GMT
Excellent stuff, thanks a lot.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.