How to create a function in Excel to validate cells using RegExs - regex

I have a long spreadsheet with tariff codes that I need to validate and I would like to create a function with RegEx to do it automatically (this is a daily task that I will have to do for the following months and I would like to automatize)
For example in Column A, I have the following data:
CODE
1000.00.00
1000.10.00
1020.12.99
...
But some times, the codes are mispelled like (1020..23.99 or 1020.23.124), and I would like to make a validation in column B with a function like this in each cell:
=isvalid_function(A2,"^\d{3,4}\.\d{2}\.\d{2}$")
..and get TRUE or FALSE as result.

You need to add the reference to Microsoft VBScript Regular Expressions to Excel, then you can use Regex, see this link for some more detail. Then you'd create a UDF called isvalid_function that would implement that.

Related

Data validation for time input in Google Sheets

I am searching for a solution that would allow users to insert time values only in this format: hh:mm, and reject if something else is inserted. Something similar like data validation for date - Data validation -> Is valid date -> Reject input.
I tried to search and adjust a Regexmatch formula for this one, with no success, but I am open for other suggestions also.
Thank you in advance!
SUGGESTION
Perhaps you can try using a more specific regex such as the one sample from this existing post. Then, apply it your data validation via a custom function using REGEXMATCH function as seen here:
=REGEXMATCH(TO_TEXT(A1),"^([0-1]?[0-9]|2[0-3]):[0-5][0-9]$")
Sample Data Validation Config:
Demo:
E.g. Any text or date formats won't be accepted.
use custom formula:
=REGEXMATCH(""&A1; "\d{2}:\d{2}")
if you want to block inputs like: 75:99 then try:
=REGEXMATCH(""&A1; "\d{2}:\d{2}")*((A1*1)<=1)

Extract column value using REGEXEXTRACT with ARRAYFORMULA

I have a column in Google Sheets with values like 1(current), 2(current), etc. I am getting these values from google form response.
I want to extract only the integer from cell value as 1,2,3.. so on.
I am able to use SPLIT(A2, "(current)") for cells. But this does not get applied for new values from form response.
I found that ARRAYFORLMULA can be used for applying a formula to new responses from forms, but somehow it isn't working. I tried them as mentioned below, but I am not sure if I am using it correctly.
=ArrayFormula(QUERY( SPLIT(E2:E,"(current)")))
=ArrayFormula(SPLIT(E2:E,"(current)"))
Can someone help with how to achieve above answer with REGEXEXTRACT?
try like this:
=ARRAYFORMULA(IFNA(REGEXEXTRACT(E2:E, "\d+")))

How can I use ArrayFormula within a formula containing Vlookup, Filter and RegexMatch

I'm making a Google Spreadsheet which checks if a Value in Column A contains keywords out of a List in Column F. Problem is that I want to check if the value in A is exactly the same OR partly the same.
With a lot of help i've found over here I created this working formula:
=VLOOKUP(FILTER(ArrayFormula((LOWER(F:F)));REGEXMATCH(LOWER(A2);ArrayFormula((LOWER(F:F)))));ArrayFormula((LOWER(F:G)));1;FALSE)
Because I automatically import new lines of data I want to use ARRAYFORMULA. Unfortunately, I can't get it done.
This are my working formulas:
=VLOOKUP(FILTER(ArrayFormula((LOWER(F:F)));REGEXMATCH(LOWER(A2);ArrayFormula((LOWER(F:F)))));ArrayFormula((LOWER(F:F)));1;FALSE)
=VLOOKUP(FILTER(ArrayFormula((LOWER(F:F)));REGEXMATCH(LOWER(A3);ArrayFormula((LOWER(F:F)))));ArrayFormula((LOWER(F:F)));1;FALSE)
You can find my spreadsheet over here:
https://docs.google.com/spreadsheets/d/1aIdQ65SdeXW-4cTr8azQIiLNGcRCvTexGS_lFu8mECs/edit#gid=1308644379
=ARRAYFORMULA(PROPER(IFERROR(REGEXEXTRACT(LOWER(A2:A); LOWER(TEXTJOIN("|"; 1; F2:F))))))

OpenCart Wishlist

I'm trying to parse out the wishlist column in open cart's wishlist_to_store column to retrieve the product ID's. At first glance I thought it was being stored as JSON, but that obviously not the case. Is there a library or method I can use to parse it out?
Example wishlist:
a:2:{i:0;s:5:"16419";i:1;s:5:"16415";}
The method you are looking to use is called unserialize(). This is fairly similar in function to what JSON does but is the PHP equivalent. You can use it as follows
$a = unserialize('a:2:{i:0;s:5:"16419";i:1;s:5:"16415";}');
var_dump($a);

Parse Regular Expression in LIKE clause on Access table from within Excel

I have an old-fashioned Access database (.mdb). I have a macro-enabled Excel spreadsheet that interacts with this database via an ADODB connection.
I am wanting to perform a query on the database using a regular expression in the "like" clause; something like:
(I want to match "SM39_002xx")
"SELECT Serial from tbl1939 where Serial like RegExpMatch(""^SM+[0-9]+[_][0-9]+[a-z]?"", [Serial])"
which works perfectly within Access, but from Excel the "RegExpMatch" function isn't found and the whole thing fails.
Any help much appreciated.
User Defined Functions (UDF), which I am fairly certain is what you have in RegExpMatch, are only available within MS Access. For the most part, you should avoid creating them unless there is no other option. For example, the following query will run outside MS Access and approximates what you want:
SELECT t.Field1
FROM ATable t
WHERE t.Field1 Like "SM[0-9][0-9][_][0-9][0-9][0-9][a-z]?"