i need help writing a simple regular expresion.
I have string like:
13.03.2014 12:07:00;13.03.2014 00:00:00;Refund;4446633804;RUB;0.01;test 374383457;9645282;13.03.2014 12:05:31;1122;1122;88282;
I need to check that every column (;
) contains at least 1 characted (or just not empty).
How i can do that?
Do you think something like this?
^([^;]+;)*$
//nonzero non semicolon characters and one semicolon repeating from the beginning to the end?
It matches also empty and requires semicolon on the end. Is that what you want?
One way to do it is to use the PHP explode function to convert the string into an array. Then you can loop through the array and check each value using a simple regular expression.
$cols = explode(";", $myrecord);
$matched = preg_match('/.+/',$cols[0]);
If the element contains at least one character, $matched will be assigned a value of 1.
If you need to perform the same test on every element, then put loop through array.
just ;;
will do it. check if this is present, which means your one column is empty
if (! preg_match("^\s*;|;\s*;", $input)) {
echo "No empty columns!"
}
This simply verifies that the $input
does not start with a semi-colon, and doesn't have two successive semicolons (possibly separated by spaces) either.
Check out this regex
^\(\S+\)$