regex - regular expression pattern for string not working as I think it should -


i have following string occurs in file

stat -f -------begin------ key    : value key    : value key    : value   -------end--------- stat < d other content here stat -f -------begin------ key    : value key    : value key    : value   -------end--------- stat < d 

and want extract key value pair, not same. isn't regex correct?

^[a-z]*\s*:\s*\d+ 

i tried on here string

stat-f ------begin------ key    :     0 key    :     1 key    :     2 -------end------- stat < d 

but no match. on how regexp works in simple (as possible of course) words?

this should it:

/(\w+)\s+:\s+(\w+)/g 
  1. one or more word characters capturing group.
  2. one or more whitespace characters
  3. colon
  4. one or more whitespace characters
  5. one or more word characters capturing group.
  6. use global flag (g)

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -