@@ -19,6 +19,7 @@ experimental::[]
19
19
* <<eql-fn-match>>
20
20
* <<eql-fn-modulo>>
21
21
* <<eql-fn-multiply>>
22
+ * <<eql-fn-number>>
22
23
* <<eql-fn-startswith>>
23
24
* <<eql-fn-string>>
24
25
* <<eql-fn-stringcontains>>
@@ -805,6 +806,102 @@ If using a field as the argument, this parameter supports only
805
806
*Returns:* integer, float, or `null`
806
807
====
807
808
809
+ [discrete]
810
+ [[eql-fn-number]]
811
+ === `number`
812
+
813
+ Converts a string to the corresponding integer or float.
814
+
815
+ [%collapsible]
816
+ ====
817
+ *Example*
818
+ [source,eql]
819
+ ----
820
+ number("1337") // returns 1337
821
+ number("42.5") // returns 42.5
822
+ number("deadbeef", 16) // returns 3735928559
823
+
824
+ // integer literals beginning with "0x" are auto-detected as hexadecimal
825
+ number("0xdeadbeef") // returns 3735928559
826
+ number("0xdeadbeef", 16) // returns 3735928559
827
+
828
+ // "+" and "-" are supported
829
+ number("+1337") // returns 1337
830
+ number("-1337") // returns -1337
831
+
832
+ // surrounding whitespace is ignored
833
+ number(" 1337 ") // returns 1337
834
+
835
+ // process.pid = "1337"
836
+ number(process.pid) // returns 1337
837
+
838
+ // null handling
839
+ number(null) // returns null
840
+ number(null, 16) // returns null
841
+
842
+ // strings beginning with "0x" are treated as hexadecimal (base 16),
843
+ // even if the <base_num> is explicitly null.
844
+ number("0xdeadbeef", null) // returns 3735928559
845
+
846
+ // otherwise, strings are treated as decimal (base 10)
847
+ // if the <base_num> is explicitly null.
848
+ number("1337", null) // returns 1337
849
+ ----
850
+
851
+ *Syntax*
852
+ [source,txt]
853
+ ----
854
+ number(<string>[, <base_num>])
855
+ ----
856
+
857
+ *Parameters*
858
+
859
+ `<string>`::
860
+ +
861
+ --
862
+ (Required, string or `null`)
863
+ String to convert to an integer or float. If this value is a string, it must be
864
+ one of the following:
865
+
866
+ * A string representation of an integer (e.g., `"42"`)
867
+ * A string representation of a float (e.g., `"9.5"`)
868
+ * If the `<base_num>` parameter is specified, a string containing an integer
869
+ literal in the base notation (e.g., `"0xDECAFBAD"` in hexadecimal or base
870
+ `16`)
871
+
872
+ Strings that begin with `0x` are auto-detected as hexadecimal and use a default
873
+ `<base_num>` of `16`.
874
+
875
+ `-` and `+` are supported with no space between. Surrounding whitespace is
876
+ ignored. Empty strings (`""`) are not supported.
877
+
878
+ If using a field as the argument, this parameter supports only the following
879
+ field datatypes:
880
+
881
+ * <<keyword,`keyword`>>
882
+ * <<constant-keyword,`constant_keyword`>>
883
+ * <<text,`text`>> field with a <<keyword,`keyword`>> or
884
+ <<constant-keyword,`constant_keyword`>> sub-field
885
+
886
+ If this argument is `null`, the function returns `null`.
887
+ --
888
+
889
+ `<base_num>`::
890
+ +
891
+ --
892
+ (Optional, integer or `null`)
893
+ Radix or base used to convert the string. If the `<string>` begins with `0x`,
894
+ this parameter defaults to `16` (hexadecimal). Otherwise, it defaults to base
895
+ `10`.
896
+
897
+ If this argument is explicitly `null`, the default value is used.
898
+
899
+ Fields are not supported as arguments.
900
+ --
901
+
902
+ *Returns:* integer or float or `null`
903
+ ====
904
+
808
905
[discrete]
809
906
[[eql-fn-startswith]]
810
907
=== `startsWith`
0 commit comments