hasMatch
hasMatch(text: String, regex: Regex<T>) : Bool
Checks whether text matches the structure specified by regex. The entirety of text must match.
Examples
| Example | Result |
|---|---|
hasMatch("", re``) | true |
hasMatch(" ", re``) | false |
hasMatch("Name: Jane, Age: 32", re`Name: (\w+), Age: (\d+)`) | true |
hasMatch("", re`Name: (\w+), Age: (\d+)`) | false |
hasMatch("192.168.0.1", re`\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b`) | true |
hasMatch("1.2.3x4", re`\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b`) | false |
hasMatch("device-config.txt", re`[^ ]*\.txt`) | true |
hasMatch("device config.org", re`[^ ]*\.txt`) | false |
hasMatch("2357", re`(?<age:Number>\w+)`) | true |
hasMatch("3x", re`(?<age:Number>\w+)`) | false |
hasMatch("3.14", re`(?<age:Float>\d+.\d+)`) | true |
hasMatch("3.14", re`(?<age:Float>\w+)`) | false |
hasMatch("2.4.6.8", re`(?<age:IpAddress>\d.\d.\d.\d)`) | true |
hasMatch("a.b.c.d", re`(?<age:IpAddress>\w+)`) | false |
See also
Functions
- match: Gets a record of information about text that matches the structure specified by a regex,
or otherwise
null. - regexMatches: Gets the list of all substring matches of a given regex.