XPath: Matches
<
The matches() function in XPath is used to select elements that match a specific regular expression pattern. This function is powerful for identifying elements based on complex string patterns, such as dates, phone numbers, or any other text format.
You can use the following XPath:
This selects list items (li) within an unordered list (ul) where the text content matches the regular expression pattern (\d{2}/\d{2}/\d{4}), which represents a date in the format MM/DD/YYYY. The i flag indicates that the matching is case-insensitive.
Example 1 : //ul[@class='list-group']/li[matches(.,'(\d{2}/\d{2}/\d{4})$',i)]
- 02/01/25
- 01/01/2025
- 12/31/2024
- 12/30/2024
- 12/29/2024
- 12/28/2024
- 12/27/2024
- 12/26/2024
- 12/25/2024
- 12/24/2024
- 12/23/2024