tags:

views:

72

answers:

2

EG something of the form: 12. or 1. or 143. Thanks.

+4  A: 

This is it:

^\d+\.$
Alex LE
In general, you can put a period literal in a regex by escaping it with a backslash.
zenazn
If "number followed by a period" means "string of digits 0-9 followed by a period", then this is a great answer (but I don't see anything in the question to justify the ^ and $ anchors). Depending on context, "4e-3" is a number, as is "0xdeadbeef", and "3/4". The question is ill formed.
William Pursell
Well, that's why I put some examples in the question. If I wanted base 16, exponents, fractions ect, I would have been more specific. Regardless I'll try and be more exact next time (I don't have much call to use REGEX so it's pretty poor.)
aslum
Sometimes you'll see `[.]`, it has the same effect as `\.`.
ephemient
Some older implementations of regex don't have the `\d` character class. `[0-9]` is a bit more universal.
R Samuel Klatchko
+3  A: 

The following will match all of your examples, and should work with any regex implementation:

[0-9]+\.
Daniel
Sure, it works with most modern regex engines and programs using POSIX extended RE (bash, egrep), but won't work with programs using POSIX basic RE (expr, grep, sed, vi): those require `[0-9]\+\.`.
ephemient