1
- .. contents ::
2
- :depth: 3
3
- ..
4
-
5
1
pygrok |Build Status |
6
2
=====================
7
3
@@ -38,13 +34,34 @@ Getting Started
38
34
39
35
.. code :: Python
40
36
41
- >> > import pygrok
42
- >> > text = ' gary is male, 25 years old and weighs 68.5 kilograms'
43
- >> > pattern = ' %{WORD: name} is %{WORD: gender} , %{NUMBER: age} years old and weighs %{NUMBER: weight} kilograms'
44
- >> > print pygrok.grok_match(text, pattern)
45
- {' gender' : ' male' , ' age' : ' 25' , ' name' : ' gary' , ' weight' : ' 68.5' }
37
+ from pygrok import Grok
38
+ text = ' gary is male, 25 years old and weighs 68.5 kilograms'
39
+ pattern = ' %{WORD: name} is %{WORD: gender} , %{NUMBER: age} years old and weighs %{NUMBER: weight} kilograms'
40
+ grok = Grok(pattern)
41
+ print grok.match(text)
42
+
43
+ # {'gender': 'male', 'age': '25', 'name': 'gary', 'weight': '68.5'}
44
+
45
+ Pretty Cool !
46
+
47
+ Numbers can be converted from string to ``int `` or ``float `` if you use
48
+ ``%{pattern:name:type} `` syntax, such as ``%{NUMBER:age:int} ``
49
+
50
+ .. code :: Python
46
51
47
- Pretty Cool ! Some of the pattern you can use are listed here:
52
+ from pygrok import Grok
53
+ text = ' gary is male, 25 years old and weighs 68.5 kilograms'
54
+ pattern = ' %{WORD: name} is %{WORD: gender} , %{NUMBER: age:int} years old and weighs %{NUMBER: weight:float} kilograms'
55
+ grok = Grok(pattern)
56
+ print grok.match(text, pattern)
57
+
58
+ # {'gender': 'male', 'age': 25, 'name': 'gary', 'weight': 68.5}
59
+
60
+ Now ``age `` is of type ``int `` and ``weight `` is of type ``float ``.
61
+
62
+ Awesome !
63
+
64
+ Some of the pattern you can use are listed here:
48
65
49
66
::
50
67
@@ -56,6 +73,9 @@ Pretty Cool ! Some of the pattern you can use are listed here:
56
73
57
74
See All patterns `here <./pygrok/patterns >`__
58
75
76
+ You can also have custom pattern, see `these
77
+ codes <https://github.com/garyelephant/pygrok/blob/master/tests/test_pygrok.py#L97> `__.
78
+
59
79
More details
60
80
------------
61
81
0 commit comments