#26Server Log Pattern Matching
A server monitoring system receives log messages continuously. To automatically detect specific types of events, an administrator defines a log pattern that can contain normal characters and two special symbols.
You are given: A log message s A monitoring pattern p
The pattern follows these rules: . matches exactly one arbitrary character.
- matches zero or more occurrences of the character immediately before it. The pattern must match the entire log message, not just a part of it.
Determine whether the complete log message matches the monitoring pattern. Return true if it matches; otherwise, return false.
Real-World Context This type of matching can be used in: Server log monitoring; Error and exception detection; Cybersecurity log analysis; Automated alert systems; System health monitoring
Examples
Example 1
Input: s = "error"
p = "e.*r"
Output: true
Explanation: "e.*r" matches "error" because e matches the first e, .* matches "rro", and the final r matches the last r.
Example 2
Input: s = "warning"
p = "w.*g"
Output: true
Explanation: w matches w, .* matches "arnin", and g matches the final character.
Example 3
Input: s = "failed"
p = "fail.*x"
Output: false
Explanation: The pattern requires the complete message to end with x, but the message ends with d.
Constraints
- 0 ≤ s.length ≤ 20
- 1 ≤ p.length ≤ 20
- s contains lowercase English letters and digits.
- p contains lowercase English letters, digits, . and *.
- Matching is case-sensitive.
- The pattern contains no standalone *.
- The entire string s must match p.
