Q:

Break strings into substrings based on delimiters, with empty substrings

I am using LUA to create a table within a table, and am running into an issue. I need to also populate the NIL values that appear, but can not seem to get it right. 
String being manipulated: 
PatID = '07-26-27~L73F11341687Per^^^SCI^SP~N7N558300000Acc^'

for word in PatID:gmatch("[^\~w]+") do table.insert(PatIDTable,word) end
local _, PatIDCount = string.gsub(PatID,"~","")

PatIDTableB = {}
for i=1, PatIDCount+1 do
   PatIDTableB[i] = {}
end

for j=1, #PatIDTable do
 for word in PatIDTable[j]:gmatch("[^\^]+") do
  table.insert(PatIDTableB[j], word)         
 end
end

This currently produces this output:
table
[1]=table
 [1]='07-26-27'
[2]=table
 [1]='L73F11341687Per'
 [2]='SCI'
 [3]='SP'
[3]=table
 [1]='N7N558300000Acc'

But I need it to produce:
table
[1]=table
 [1]='07-26-27'
[2]=table
 [1]='L73F11341687Per'
 [2]=''
 [3]=''
 [4]='SCI'
 [5]='SP'
[3]=table
 [1]='N7N558300000Acc'
 [2]=''

EDIT:
I think I may have done a bad job explaining what it is I am looking for. It is not necessarily that I want the karats to be considered "NIL" or "empty", but rather, that they signify that a new string is to be started. 
They are, I guess for lack of a better explanation, position identifiers. 
So, for example:
L73F11341687Per^^^SCI^SP 

actually translates to:
1. L73F11341687Per
2. 
3. 
4. SCI
5. SP

If I were to have
L73F11341687Per^12ABC^^SCI^SP

Then the positions are:
1. L73F11341687Per
2. 12ABC
3. 
4. SCI
5. SP

And in turn, the table would be:
table
[1]=table
 [1]='07-26-27'
[2]=table
 [1]='L73F11341687Per'
 [2]='12ABC'
 [3]=''
 [4]='SCI'
 [5]='SP'
[3]=table
 [1]='N7N558300000Acc'
 [2]=''

Hopefully this sheds a little more light on what I'm trying to do.

A:

Now that we've cleared up what the question is about, here's the issue.
Your gmatch pattern will return all of the matching substrings in the given string. However, your gmatch pattern uses "+". That means "one or more", which therefore cannot match an empty string. If it encounters a ^ character, it just skips it.
But, if you just tried :gmatch("[^\^]*"), which allows empty matches, the problem is that it would effectively turn every ^ character into an empty match. Which is not what you want.
What you want is to eat the ^ at the end of a substring. But, if you try :gmatch("([^\^])\^"), you'll find that it won't return the last string. That's because the last string doesn't end with ^, so it isn't a valid match.
The closest you can get with gmatch is this pattern: "([^\^]*)\^?". This has the downside of putting an empty string at the end. However, you can just remove that easily enough, since one will always be placed there.

