Solved

Regular Expressions

Posted on 2008-10-18
5
251 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
Comment Utility
\\.\\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
Comment Utility
\\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
Comment Utility
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
Comment Utility
See my second message ;)

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

Author Comment

by:gem56
Comment Utility
yep, beat me to the post :P

thanks champ

0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
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:

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now