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.2014g fulfils 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

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -