match a specific decimal number 0.666666

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
rtaylor
Forum Newbie
Posts: 1
Joined: Sat Jan 29, 2011 8:56 am

match a specific decimal number 0.666666

Post by rtaylor »

Hi,

I am entirely new to regex. I need to use regular-expression to match correct answers for an online quiz. Is there any expression for matching a decimal number that may be entered in a number of different ways. For example,

0.666666...

could match
.66, .67, .66666, .667, 0.6667 etc.

thanks,

~russ
User avatar
greyhoundcode
Forum Regular
Posts: 613
Joined: Mon Feb 11, 2008 4:22 am

Re: match a specific decimal number 0.666666

Post by greyhoundcode »

How about this one:

Code: Select all

^0?\.6+7?$
You'd need to trim out any whitespace from the answer first of all.
Post Reply