Vidhi
Vidhi

Reputation: 35

Regular Expression in Java to find the colon in the string

I want to distinguish the Strings between the string contains integer at the end and the String contains integer at the end but does not have a colon in it. I try to find the solution a bit but not succeed. I am new to a regular expression. What I have tried so far is.

("^.+?\\d$")) works good if the string is libbz2-1.0

But in this case for this input "lighttpd:i386" it treats the same way as it contains the integer at the end. I am not able to tell that treat it in a different way as it contains the colon in it.Any help would be greatly appreciated.

Upvotes: 0

Views: 1453

Answers (2)

CrazySabbath
CrazySabbath

Reputation: 1334

Not an expert with regular expressions (try to avoid them if possible), but:

This would match any string not containing colon and digit:

^(?!.*:).+?\d$

link to regex

This would match any String containing colon and digit:

^(?:.*:).+?\d$

link to regex

Upvotes: 1

user9413725
user9413725

Reputation: 1

Try ^.+?[^\\:]\d. This will negate colon from your output. So all strings like abcd:09 will be ignored.

Upvotes: 0

Related Questions