\documentclass{article}
\usepackage{etoolbox}
\usepackage{xstring}
\usepackage{xcolor}
\newcommand{\stringToNumberTabTable}{}
\newcommand{\stringToNumberFigTable}{}
\newcounter{StringCounterTab}
\setcounter{StringCounterTab}{1}
\newcounter{StringCounterFig}
\setcounter{StringCounterFig}{1}
\newcommand*\mytmp{}
\newcommand*\myStrBetween[3]{%
\StrBehind{#1}{#2}[\mytmp]%
\typeout{+++ (\mytmp)}%
\StrBefore{\mytmp}{#3}%
}
\newcommand{\nr}[1]{
\StrLeft{#1}{5}[\firstFiveCharsOfFirstString]
\StrLeft{SITab}{5}[\firstFiveCharsOfSecondString]
\StrLeft{SIFig}{5}[\firstFiveCharsOfThirdString]
\IfStrEq{\firstFiveCharsOfFirstString}{\firstFiveCharsOfSecondString}{\IfSubStr{\stringToNumberTabTable}{#1}{S\myStrBetween{\stringToNumberTabTable}{#1:}{;}}{\colorbox{red}{Label for table not defined.}}}{\IfStrEq{\firstFiveCharsOfFirstString}{\firstFiveCharsOfThirdString}{\IfSubStr{\stringToNumberFigTable}{#1}{S\myStrBetween{\stringToNumberFigTable}{#1:}{;}}{\colorbox{red}{Label for figure not defined.}}}{\ref{#1}}}}
\newcommand{\nl}[1]{
\StrLeft{#1}{5}[\firstFiveCharsOfFirstString]
\StrLeft{SITab}{5}[\firstFiveCharsOfSecondString]
\StrLeft{SIFig}{5}[\firstFiveCharsOfThirdString]
\IfStrEq{\firstFiveCharsOfFirstString}{\firstFiveCharsOfSecondString}
{\IfSubStr{\stringToNumberTabTable}{#1}{\colorbox{red}{Label already defined!}}{\edef\stringToNumberTabTable{\stringToNumberTabTable#1:\arabic{StringCounterTab};}\stepcounter{StringCounterTab}\relax}}{\IfStrEq{\firstFiveCharsOfFirstString}{\firstFiveCharsOfThirdString}{\IfSubStr{\stringToNumberFigTable}{#1}{\colorbox{red}{Label already defined!}}{\edef\stringToNumberFigTable{\stringToNumberFigTable#1:\arabic{StringCounterFig};}\stepcounter{StringCounterFig}\relax}}{\label{#1}}}
}
%Minimalbeispiel