I need a function in R that mimics the functionality of LIKE in MySQL.
(I need to validate outcomes of SQL queries and R scripts against each other. If I had a function that exists to mimic the functionality of LIKE, great, that reduces my workload.)
I am adding some of the behaviors of LIKE from the link above. As you can see, there are ways in which LIKE differs from the standard grep regex.
LIKE (description from the link)
- Pattern matching using SQL simple regular expression comparison. Returns 1 (TRUE) or 0 (FALSE).
- Per the SQL standard, LIKE performs matching on a per-character basis, thus it can produce results different from the = comparison operator:
- Trailing spaces are significant
- With LIKE you can use the following two wildcard characters in the pattern. Character Description % Matches any number of characters, even zero characters _ Matches exactly one character
In MySQL, LIKE is permitted on numeric expressions. (This is an extension to the standard SQL LIKE.)
mysql> SELECT 10 LIKE '1%'; -> 1