IsMatch

Learn about the IsMatch OTTL converter function.

The IsMatch converter checks if a string matches a regular expression pattern and returns a boolean value.

Syntax: IsMatch(value, pattern)

  • value: the string field to check
  • pattern: the regular expression pattern to match against

Input

{
	"_type": "log",
	"body": "User authentication successful",
	"resource": {...},
	"attributes": {
		"email": "user@example.com",
		"phone": "555-123-4567",
		"ip_address": "192.168.1.100"
	}
}

Statement

set(attributes["is_valid_email"], IsMatch(attributes["email"], "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$"))
set(attributes["is_valid_phone"], IsMatch(attributes["phone"], "^\\d{3}-\\d{3}-\\d{4}$"))
set(attributes["is_private_ip"], IsMatch(attributes["ip_address"], "^(10\\.|172\\.(1[6-9]|2[0-9]|3[01])\\.|192\\.168\\.)"))

Output

{
	"_type": "log",
	"body": "User authentication successful",
	"resource": {...},
	"attributes": {
		"email": "user@example.com",
		"phone": "555-123-4567",
		"ip_address": "192.168.1.100",
		"is_valid_email": true,
		"is_valid_phone": true,
		"is_private_ip": true
	}
}

The IsMatch function validated the email format, phone number format, and identified the IP as private.