Better: use a key-value syntax.
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\exercice}{O{}}
{
\group_begin:
\keys_set:nn { projetmbc/ex } { #1 }
\par\vspace{\topsep}\noindent Exercice
\tl_if_empty:NF \l_projetembc_ex_pts_tl
{ ~(\tl_use:N \l_projetembc_ex_pts_tl\nobreakspace pts) }
\tl_if_empty:NF \l_projetembc_ex_note_tl
{ ~[\tl_use:N \l_projetembc_ex_note_tl] }
\group_end:
\quad\ignorespaces
}
\keys_define:nn { projetmbc/ex }
{
points .tl_set:N = \l_projetembc_ex_pts_tl ,
note .tl_set:N = \l_projetembc_ex_note_tl ,
}
\ExplSyntaxOff
\begin{document}
\exercice Text
\exercice[points=2] Text
\exercice[note=Source: folklore] Text
\exercice[points=4,note=Source: folklore] Text
\end{document}

\exercise
,\exercise[2]
and\exercise[2][Source: ...]
. Withxparse
package you can do\NewDocumentCommand\exercise{oo}{Exercise\IfValueT{#1}{ (#1 pts)}\IfValueT{#2}{ [#2]}}
which defines\exercise[..][..]
; and if you substituteoo
forgg
in the defintion you will define what you asked for:\exercise{..}{..}
. – Manuel Oct 25 '17 at 14:05\NewDocumentCommand
. I did not know it. – projetmbc Oct 25 '17 at 19:03