Skip to content

Commit 14a77d3

Browse files
committed
update README
1 parent 91cea34 commit 14a77d3

File tree

2 files changed

+44
-18
lines changed

2 files changed

+44
-18
lines changed

README.md

+14-8
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,26 @@ or download, uncompress and install pygrok from [here](https://github.com/garyel
2929
Getting Started
3030
---------------
3131
```Python
32-
>>> import pygrok
33-
>>> text = 'gary is male, 25 years old and weighs 68.5 kilograms'
34-
>>> pattern = '%{WORD:name} is %{WORD:gender}, %{NUMBER:age} years old and weighs %{NUMBER:weight} kilograms'
35-
>>> print pygrok.grok_match(text, pattern)
36-
{'gender': 'male', 'age': '25', 'name': 'gary', 'weight': '68.5'}
32+
from pygrok import Grok
33+
text = 'gary is male, 25 years old and weighs 68.5 kilograms'
34+
pattern = '%{WORD:name} is %{WORD:gender}, %{NUMBER:age} years old and weighs %{NUMBER:weight} kilograms'
35+
grok = Grok(pattern)
36+
print grok.match(text)
37+
38+
# {'gender': 'male', 'age': '25', 'name': 'gary', 'weight': '68.5'}
3739
```
3840

3941
Pretty Cool !
4042

4143
Numbers can be converted from string to `int` or `float` if you use `%{pattern:name:type}` syntax, such as `%{NUMBER:age:int}`
4244
```Python
43-
>>> pattern = '%{WORD:name} is %{WORD:gender}, %{NUMBER:age:int} years old and weighs %{NUMBER:weight:float} kilograms'
44-
>>> print pygrok.grok_match(text, pattern)
45-
{'gender': 'male', 'age': 25, 'name': 'gary', 'weight': 68.5}
45+
from pygrok import Grok
46+
text = 'gary is male, 25 years old and weighs 68.5 kilograms'
47+
pattern = '%{WORD:name} is %{WORD:gender}, %{NUMBER:age:int} years old and weighs %{NUMBER:weight:float} kilograms'
48+
grok = Grok(pattern)
49+
print grok.match(text, pattern)
50+
51+
# {'gender': 'male', 'age': 25, 'name': 'gary', 'weight': 68.5}
4652
```
4753
Now `age` is of type `int` and `weight` is of type `float`.
4854

README.rst

+30-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
.. contents::
2-
:depth: 3
3-
..
4-
51
pygrok |Build Status|
62
=====================
73

@@ -38,13 +34,34 @@ Getting Started
3834

3935
.. code:: Python
4036
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
4651
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:
4865

4966
::
5067

@@ -56,6 +73,9 @@ Pretty Cool ! Some of the pattern you can use are listed here:
5673

5774
See All patterns `here <./pygrok/patterns>`__
5875

76+
You can also have custom pattern, see `these
77+
codes <https://github.com/garyelephant/pygrok/blob/master/tests/test_pygrok.py#L97>`__.
78+
5979
More details
6080
------------
6181

0 commit comments

Comments
 (0)