Not using expl3 I can offer a generic mechanism \UD@CheckWhetherLeadingTokens
for detecting whether a macro argument's leading tokens form a specific token-sequence.
\UD@CheckWhetherLeadingTokens
requires an ⟨internal token-check-macro⟩ that processes a macro-argument delimited by that specific token-sequence.
The fact that the specific token-sequence is used as an argument-delimiter implies that the specific token-sequence cannot contain explicit character tokens of category 1(begin group) or 2(end group) or 6(parameter).
Syntax is:
\UD@CheckWhetherLeadingTokens{⟨argument which is to be checked⟩}%
{⟨a ⟨token sequence⟩ without explicit
character tokens of category 1 or 2
or 6⟩}%
{⟨internal token-check-macro⟩}%
{⟨tokens to be delivered in case
⟨argument which is to be checked⟩ has
⟨token sequence⟩ as leading tokens⟩}%
{⟨tokens to be delivered in case
⟨argument which is to be checked⟩
does not have ⟨token sequence⟩ as
leading tokens⟩}%
For defining the ⟨internal token-check-macro⟩ with the delimited argument you can use
\UD@internaltokencheckdefiner{⟨internal token-check-macro⟩}%
{⟨token-sequence-gobble-macro⟩}%
{⟨token sequence⟩}%
⟨token-sequence-gobble-macro⟩ is not used by \UD@CheckWhetherLeadingTokens
but it can be used for gobbling the leading token-sequence.
Here is the MWE:
\documentclass{article}
\makeatletter
%%=============================================================================
%% Paraphernalia:
%% \UD@firstoftwo, \UD@secondoftwo, \UD@Exchange, \UD@stopromannumeral,
%% \UD@CheckWhetherNull, \UD@CheckWhetherLeadingTokens
%%=============================================================================
\newcommand\UD@firstoftwo[2]{#1}%
\newcommand\UD@secondoftwo[2]{#2}%
\newcommand\UD@Exchange[2]{#2#1}%
\@ifdefinable\UD@stopromannumeral{\chardef\UD@stopromannumeral=`\^^00}%
%%-----------------------------------------------------------------------------
%% Check whether argument is empty:
%%.............................................................................
%% \UD@CheckWhetherNull{<Argument which is to be checked>}%
%% {<Tokens to be delivered in case that argument
%% which is to be checked is empty>}%
%% {<Tokens to be delivered in case that argument
%% which is to be checked is not empty>}%
%%
%% The gist of this macro comes from Robert R. Schneck's \ifempty-macro:
%% <https://groups.google.com/forum/#!original/comp.text.tex/kuOEIQIrElc/lUg37FmhA74J>
\newcommand\UD@CheckWhetherNull[1]{%
\romannumeral\expandafter\UD@secondoftwo\string{\expandafter
\UD@secondoftwo\expandafter{\expandafter{\string#1}\expandafter
\UD@secondoftwo\string}\expandafter\UD@firstoftwo\expandafter{\expandafter
\UD@secondoftwo\string}\expandafter\UD@stopromannumeral\UD@secondoftwo}{%
\expandafter\UD@stopromannumeral\UD@firstoftwo}%
}%
%%-----------------------------------------------------------------------------
%% Check whether argument's leading tokens form a specific
%% token-sequence that does not contain explicit character tokens of
%% category 1 or 2 or 6:
%%.............................................................................
%% \UD@CheckWhetherLeadingTokens{<argument which is to be checked>}%
%% {<a <token sequence> without explicit
%% character tokens of category 1 or 2
%% or 6>}%
%% {<internal token-check-macro>}%
%% {<tokens to be delivered in case
%% <argument which is to be checked> has
%% <token sequence> as leading tokens>}%
%% {<tokens to be delivered in case
%% <argument which is to be checked>
%% does not have <token sequence> as
%% leading tokens>}%
\newcommand\UD@CheckWhetherLeadingTokens[3]{%
\romannumeral\UD@CheckWhetherNull{#1}%
{\expandafter\UD@stopromannumeral\UD@secondoftwo}%
{%
% Let's nest things into \UD@firstoftwo{...}{} to make sure they are nested in braces
% and thus do not disturb when the test is carried out within \halign/\valign:
\expandafter\UD@firstoftwo\expandafter{%
\expandafter\expandafter\expandafter\UD@stopromannumeral
\romannumeral
\expandafter\UD@secondoftwo\string{\expandafter\UD@@CheckWhetherLeadingTokens#3{\relax}#1#2}{}}{}%
}%
}%
\newcommand\UD@@CheckWhetherLeadingTokens[1]{%
\expandafter\UD@CheckWhetherNull\expandafter{\UD@firstoftwo{}#1}%
{\UD@Exchange{\UD@firstoftwo}}{\UD@Exchange{\UD@secondoftwo}}%
{\expandafter\expandafter\expandafter\UD@stopromannumeral
\expandafter\expandafter\expandafter}%
\expandafter\UD@secondoftwo\expandafter{\string}%
}%
%%-----------------------------------------------------------------------------
%% \UD@internaltokencheckdefiner{<internal token-check-macro>}%
%% {<token-sequence-gobble-macro>}%
%% {<token sequence>}%
%% - Defines <internal token-check-macro> to snap everything
%% until reaching <token sequence> and spit that out,
%% nested in braces. <token sequence> is discarded.
%% - Defines <token-sequence-gobble-macro> to gobble/discard
%% everything until reaching <token sequence>.
%% <token sequence> is discarded, too.
%% <token sequence> must not contain explicit character tokens
%% of category 1 or 2 or 6.
%%-----------------------------------------------------------------------------
\newcommand\UD@internaltokencheckdefiner[3]{%
\@ifdefinable#1{\long\def#1##1#3{{##1}}}%
\@ifdefinable#2{\def#2#3{}}%
}%
%------------------------------------------------------------------------------
\UD@internaltokencheckdefiner{\UD@Checkmyspace}{\UD@Gobblemyspace}{my }%
\UD@internaltokencheckdefiner{\UD@CheckMyspace}{\UD@GobbleMyspace}{My }%
\UD@internaltokencheckdefiner{\UD@CheckmYspace}{\UD@GobblemYspace}{mY }%
\UD@internaltokencheckdefiner{\UD@CheckMYspace}{\UD@GobbleMYspace}{MY }%
%\UD@internaltokencheckdefiner{\UD@Checkmy}{\UD@Gobblemy}{my}%
%\UD@internaltokencheckdefiner{\UD@CheckMy}{\UD@GobbleMy}{My}%
%\UD@internaltokencheckdefiner{\UD@CheckmY}{\UD@GobblemY}{mY}%
%\UD@internaltokencheckdefiner{\UD@CheckMY}{\UD@GobbleMY}{MY}%
%------------------------------------------------------------------------------
\@ifdefinable\UD@gobbletospace{\long\def\UD@gobbletospace#1 {}}%
\newcommand\UD@CheckWhetherNoSpace[1]{%
\expandafter\UD@CheckWhetherNull\expandafter{\UD@gobbletospace#1 }%
}%
%------------------------------------------------------------------------------
\newcommand\transform[1]{%
\UD@CheckWhetherLeadingTokens{#1}{my }{\UD@Checkmyspace}{\textbf{\UD@Gobblemyspace#1}}{%
\UD@CheckWhetherLeadingTokens{#1}{My }{\UD@CheckMyspace}{\textbf{\UD@GobbleMyspace#1}}{%
\UD@CheckWhetherLeadingTokens{#1}{mY }{\UD@CheckmYspace}{\textbf{\UD@GobblemYspace#1}}{%
\UD@CheckWhetherLeadingTokens{#1}{MY }{\UD@CheckMYspace}{\textbf{\UD@GobbleMYspace#1}}{%
% \UD@CheckWhetherLeadingTokens{#1}{my }{\UD@Checkmy}{\textbf{\UD@Gobblemy#1}}{%
% \UD@CheckWhetherLeadingTokens{#1}{My }{\UD@CheckMy}{\textbf{\UD@GobbleMy#1}}{%
% \UD@CheckWhetherLeadingTokens{#1}{mY }{\UD@CheckmY}{\textbf{\UD@GobblemY#1}}{%
% \UD@CheckWhetherLeadingTokens{#1}{MY }{\UD@CheckMY}{\textbf{\UD@GobbleMY#1}}{%
\textit{\UD@CheckWhetherNoSpace{#1}{}{\UD@gobbletospace}#1}%
% }%
% }%
% }%
% }%
}%
}%
}%
}%
}%
%------------------------------------------------------------------------------
\makeatother
\begin{document}
\verb|\transform{my big world}|: \transform{my big world}
\verb|\transform{our small world}|: \transform{our small world}
\verb|\transform{your world}|: \transform{your world}
\verb|\transform{My world}|: \transform{My world}
\verb|\transform{My }|: \transform{My }
\verb|\transform{My}|: \transform{My}
\verb|\transform{Bla}|: \transform{Bla}
\end{document}

You did not specify desired behavior in case the argument contains no spaces. In this case the argument is delivered in \textit
without anything being removed.
If you need different behavior let me know via a comment and I will edit my answer accordingly.
\UD@CheckWhetherLeadingTokens
does not change the letter-casing of any component of its first argument and thus \transform
does not change the letter-casing of any component of its argument.
Occurrence of marker-tokens/sentinel-tokens like \@nil
within the argument of \transform
/within the first argument of \UD@CheckWhetherLeadingTokens
is not forbidden.
Unmatched \if..
or \else
or \or
or \fi
or \csname
or \endcsname
may occur within the first argument of \UD@CheckWhetherLeadingTokens
. However with \transform
things are passed on to the LaTeX 2ε-kernel-macros\textit
/\textbf
which don't handle such unmatched things.
\UD@CheckWhetherLeadingTokens
and thus \transform
itself work by means of expansion only. This means carrying out any of the macros belonging to the mechanism for finding out whether the argument has a leading token-sequence my⟨space⟩
/My⟨space⟩
/mY⟨space⟩
/MY⟨space⟩
does not trigger performing whatsoever temporary assignment.
\UD@CheckWhetherLeadingTokens
can be used with things like \edef
, \expanded
, \write
, \message
, \csname..\endcsname
, \number
, \romannumeral
, \ifcsname..\endcsname
, \numexpr
etc as well.
However, the LaTeX 2ε-kernel-macros \textbf
and \textit
themselves are not fully expandable and cannot reliably be used with such things. With \textbf
and \textit
both the LaTeX 2ε-kernel's \protect
-mechanism and the TeX-engine's protected
-mechanism and with old LaTeX 2ε-kernels not applying any protection-mechanism to \textbf
and \textit
at all will at least disturb things like \csname..\endcsname
, \number
, \romannumeral
\ifcsname..\endcsname
, and \numexpr
.
You can easily adapt this to using colon (:
) instad of space but be aware that there are packages which turn the colon into an active character while the mechanism below is defined while the category code of :
is 12(other).
\documentclass{article}
\makeatletter
%%=============================================================================
%% Paraphernalia:
%% \UD@firstoftwo, \UD@secondoftwo, \UD@Exchange, \UD@stopromannumeral,
%% \UD@CheckWhetherNull, \UD@CheckWhetherLeadingTokens,
%%=============================================================================
\newcommand\UD@firstoftwo[2]{#1}%
\newcommand\UD@secondoftwo[2]{#2}%
\newcommand\UD@Exchange[2]{#2#1}%
\@ifdefinable\UD@stopromannumeral{\chardef\UD@stopromannumeral=`\^^00}%
%%-----------------------------------------------------------------------------
%% Check whether argument is empty:
%%.............................................................................
%% \UD@CheckWhetherNull{<Argument which is to be checked>}%
%% {<Tokens to be delivered in case that argument
%% which is to be checked is empty>}%
%% {<Tokens to be delivered in case that argument
%% which is to be checked is not empty>}%
%%
%% The gist of this macro comes from Robert R. Schneck's \ifempty-macro:
%% <https://groups.google.com/forum/#!original/comp.text.tex/kuOEIQIrElc/lUg37FmhA74J>
\newcommand\UD@CheckWhetherNull[1]{%
\romannumeral\expandafter\UD@secondoftwo\string{\expandafter
\UD@secondoftwo\expandafter{\expandafter{\string#1}\expandafter
\UD@secondoftwo\string}\expandafter\UD@firstoftwo\expandafter{\expandafter
\UD@secondoftwo\string}\expandafter\UD@stopromannumeral\UD@secondoftwo}{%
\expandafter\UD@stopromannumeral\UD@firstoftwo}%
}%
%%-----------------------------------------------------------------------------
%% Check whether argument's leading tokens form a specific
%% token-sequence that does not contain explicit character tokens of
%% category 1 or 2 or 6:
%%.............................................................................
%% \UD@CheckWhetherLeadingTokens{<argument which is to be checked>}%
%% {<a <token sequence> without explicit
%% character tokens of category 1 or 2
%% or 6>}%
%% {<internal token-check-macro>}%
%% {<tokens to be delivered in case
%% <argument which is to be checked> has
%% <token sequence> as leading tokens>}%
%% {<tokens to be delivered in case
%% <argument which is to be checked>
%% does not have <token sequence> as
%% leading tokens>}%
\newcommand\UD@CheckWhetherLeadingTokens[3]{%
\romannumeral\UD@CheckWhetherNull{#1}%
{\expandafter\UD@stopromannumeral\UD@secondoftwo}%
{%
% Let's nest things into \UD@firstoftwo{...}{} to make sure they are nested in braces
% and thus do not disturb when the test is carried out within \halign/\valign:
\expandafter\UD@firstoftwo\expandafter{%
\expandafter\expandafter\expandafter\UD@stopromannumeral
\romannumeral
\expandafter\UD@secondoftwo\string{\expandafter\UD@@CheckWhetherLeadingTokens#3{\relax}#1#2}{}}{}%
}%
}%
\newcommand\UD@@CheckWhetherLeadingTokens[1]{%
\expandafter\UD@CheckWhetherNull\expandafter{\UD@firstoftwo{}#1}%
{\UD@Exchange{\UD@firstoftwo}}{\UD@Exchange{\UD@secondoftwo}}%
{\expandafter\expandafter\expandafter\UD@stopromannumeral
\expandafter\expandafter\expandafter}%
\expandafter\UD@secondoftwo\expandafter{\string}%
}%
%%-----------------------------------------------------------------------------
%% \UD@internaltokencheckdefiner{<internal token-check-macro>}%
%% {<token-sequence-gobble-macro>}%
%% {<token sequence>}%
%% - Defines <internal token-check-macro> to snap everything
%% until reaching <token sequence> and spit that out,
%% nested in braces. <token sequence> is discarded.
%% - Defines <token-sequence-gobble-macro> to gobble/discard
%% everything until reaching <token sequence>.
%% <token sequence> is discarded, too.
%% <token sequence> must not contain explicit character tokens
%% of category 1 or 2 or 6.
%%-----------------------------------------------------------------------------
\newcommand\UD@internaltokencheckdefiner[3]{%
\@ifdefinable#1{\long\def#1##1#3{{##1}}}%
\@ifdefinable#2{\def#2#3{}}%
}%
%------------------------------------------------------------------------------
\UD@internaltokencheckdefiner{\UD@Checkmycolon}{\UD@Gobblemycolon}{my:}%
\UD@internaltokencheckdefiner{\UD@CheckMycolon}{\UD@GobbleMycolon}{My:}%
\UD@internaltokencheckdefiner{\UD@CheckmYcolon}{\UD@GobblemYcolon}{mY:}%
\UD@internaltokencheckdefiner{\UD@CheckMYcolon}{\UD@GobbleMYcolon}{MY:}%
%------------------------------------------------------------------------------
\@ifdefinable\UD@gobbletocolon{\long\def\UD@gobbletocolon#1:{}}%
\newcommand\UD@CheckWhetherNoColon[1]{%
\expandafter\UD@CheckWhetherNull\expandafter{\UD@gobbletocolon#1:}%
}%
%------------------------------------------------------------------------------
\newcommand\transform[1]{%
\UD@CheckWhetherLeadingTokens{#1}{my:}{\UD@Checkmycolon}{\textbf{\UD@Gobblemycolon#1}}{%
\UD@CheckWhetherLeadingTokens{#1}{My:}{\UD@CheckMycolon}{\textbf{\UD@GobbleMycolon#1}}{%
\UD@CheckWhetherLeadingTokens{#1}{mY:}{\UD@CheckmYcolon}{\textbf{\UD@GobblemYcolon#1}}{%
\UD@CheckWhetherLeadingTokens{#1}{MY:}{\UD@CheckMYcolon}{\textbf{\UD@GobbleMYcolon#1}}{%
\textit{\UD@CheckWhetherNoColon{#1}{}{\UD@gobbletocolon}#1}%
}%
}%
}%
}%
}%
%------------------------------------------------------------------------------
\makeatother
\begin{document}
\verb|\transform{my:big world}| yields \transform{my:big world}
\verb|\transform{our:small world}| yields \transform{our:small world}
\verb|\transform{your:world}| yields \transform{your:world}
\verb|\transform{My:world}| yields \transform{My:world}
\verb|\transform{My:}| yields \transform{My:}
\verb|\transform{My}| yields \transform{My}
\verb|\transform{Bla}| yields \transform{Bla}
\end{document}
