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
- one or more word characters capturing group.
- one or more whitespace characters
- colon
- one or more whitespace characters
- one or more word characters capturing group.
- use global flag (g)
Comments
Post a Comment