java regex to exclude specific weight from a larger string with date -
i have string
"today 31.12.2014g receive goods. these weight 31.12g (23.03.2014)"
31.12.2014g - not mistake. text date label have g letter (without space)
i need extract string weight value (without date value), regex:
[0-9]+\.[0-9]+g
exctact date :(
my results (two group):
12.2014g
31.12g <- need this!!!
you can add negative behind make sure before part interested in there nothing don't want in case seems be
lets between 1 , 10 numbers dot after in case
31.12.2014g ^^^also make sure match entire value , not part of in case
31.12.2014g ^^^^^^^where
2.2014gfulfils condition of previous negative behind need make sure matched part should not have digit before it
so try maybe like
(?<!\\d{1,10}\\.)(?<!\\d)\\d+\\.\\d+g btw \d (which in java written "\\d") represents [0-9]. can change if want.
demo:
string data = "today 31.12.2014g receive goods. these weight 31.12g (23.03.2014)"; pattern p = pattern.compile("(?<!\\d{1,10}\\.)(?<!\\d)\\d+\\.\\d+g"); matcher m = p.matcher(data); while(m.find()) system.out.println(m.group()); output: 31.12g
Comments
Post a Comment