Solved

Regular Expressions

Posted on 2008-10-18
5
254 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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
servlet  URL Rewriting 1 42
tomcat startup error 5 102
How to convert from xls to xlsx using java 7 55
Adding multiple JVM environments to RedHat 6 7 47
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…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

840 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