Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java regex: find pattern of 1 or more numbers followed by a single

Tags:

java

regex

I'm having a java regex problem.

how can I find pattern of 1 or more numbers followed by a single . in a string?

like image 281
user840930 Avatar asked Jun 08 '12 16:06

user840930


People also ask

Which regex matches one or more digits?

+: one or more ( 1+ ), e.g., [0-9]+ matches one or more digits such as '123' , '000' . *: zero or more ( 0+ ), e.g., [0-9]* matches zero or more digits. It accepts all those in [0-9]+ plus the empty string.

How do you find multiple occurrences of a string in regex?

Method 1: Regex re. To get all occurrences of a pattern in a given string, you can use the regular expression method re. finditer(pattern, string) . The result is an iterable of match objects—you can retrieve the indices of the match using the match.

What does \\ s+ mean in regex?

The plus sign + is a greedy quantifier, which means one or more times. For example, expression X+ matches one or more X characters. Therefore, the regular expression \s matches a single whitespace character, while \s+ will match one or more whitespace characters.


2 Answers

"^[\\d]+[\\.]$"

^     = start of string
[\\d] = any digit
+     = 1 or more ocurrences
\\.   = escaped dot char
$     = end of string   
like image 164
Whimusical Avatar answered Oct 03 '22 19:10

Whimusical


(\\d)+\\.

\\d represents any digit
+ says one or more

Refer this http://www.vogella.com/articles/JavaRegularExpressions/article.html

like image 32
jmj Avatar answered Oct 03 '22 17:10

jmj