Skip to content

Commit a942a72

Browse files
committed
update Getting Started Guide
1 parent d029484 commit a942a72

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ Getting Started
3737
```
3838

3939
Pretty Cool !
40+
41+
Numbers can be converted from string to `int` or `float` if you use `%{pattern:name:type}` syntax, such as `%{NUMBER:age:int}`
42+
```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}
46+
```
47+
Now `age` is of type `int` and `weight` is of type `float`.
48+
49+
Awesome !
50+
4051
Some of the pattern you can use are listed here:
4152
```
4253
`WORD` means \b\w+\b in regular expression.
@@ -47,6 +58,8 @@ other patterns such as `IP`, `HOSTNAME`, `URIPATH`, `DATE`, `TIMESTAMP_ISO8601`,
4758
```
4859
See All patterns [here](./pygrok/patterns)
4960

61+
You can also have custom pattern, see [these codes](https://github.com/garyelephant/pygrok/blob/master/tests/test_pygrok.py#L97).
62+
5063

5164
More details
5265
------------

0 commit comments

Comments
 (0)