Solved

Regular Expressions

Posted on 2008-10-18
5
256 Views
Last Modified: 2013-11-23
hello experts,

i've been given the following regular expression "\\.\\d+|\\d+(?:\\.\\d+)?|[+-/*()%^]|\\w{3,4}|[a-zA-Z]" and im having a little trouble decoding it.

from my understanding of RE's (which isnt very much), this expression is split up into four types/categories. "[+-/*()%^]" being the normal chars, "\\w{3,4}" i would think are words of 3 or 4 letters, "[a-zA-Z]" being a letter of the alphabet, however i have absolutely no idea what the first two categories ("\\.\\d+|\\d+(?:\\.\\d+)?") represent. im guessing it has to do with numerical float values, but other then that no clue.

anyone have any idea?

cheers
0
Comment
Question by:gem56
  • 3
  • 2
5 Comments
 
LVL 11

Expert Comment

by:miqrogroove
ID: 22751216
\\.\\d+
This is a literal period, followed by one or more digits.

\\d+(?:\\.\\d+)?
This one I'm a bit confused about myself.  If I can give you a solid intrepretation I will follow up.
0
 
LVL 11

Accepted Solution

by:
miqrogroove earned 125 total points
ID: 22751224
\\d+(?:\\.\\d+)?
One or more digits followed optionally by: a literal period and one or more digits.

The syntax (?:) creates a non-backreferenced grouping, which is done only for speed optimization.

Enjoy!
0
 

Author Comment

by:gem56
ID: 22751228
thanks mate.

by the looks of it "\\d+(?:\\.\\d+)?" will probably translate to <digit>.<more digits> so looks like its just a formatting thing so it matches both "0.45" and ".45". any chance you could confirm?

cheers
0
 
LVL 11

Expert Comment

by:miqrogroove
ID: 22751235
See my second message ;)

"\\d+(?:\\.\\d+)?" will match "0.45" and not ".45"
0
 

Author Comment

by:gem56
ID: 22751302
yep, beat me to the post :P

thanks champ

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
tomcat startup error 5 132
ejb on wildfly 5 45
Need Help! Getting a syntax error and don't understand why 3 38
Netbeans and org.apache.commons.lang3 issue 3 22
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question