Skip to main content
added 110 characters in body
Source Link
Night2
  • 6k
  • 1
  • 14
  • 46

PHP (7.4), 148148 143 bytes

-5 bytes by stealing RegEx idea from @Arnauld.

<?=preg_replace_callback('/[@_]\w+(".*?="|([^"]*"[^"]*")*[^"]*$[@_]\w+)/',fn($m)=>['=>$m[1]?[':'][$m[0][0]>A].($_GET[$w=substr($m[0],1)]?:$_GET[$w]=++$_GET[0]):$m[0],$argv[1]);

Try it online!Try it online!

Define labels with @ and refer to them with _.

Captures any @<label> or _<label> which aren't inside double quotes ("...") and replaces them with a unique number for every unique label, starting from 1. Also adds the : when replacing labels that have @ before them.

PHP's global variable $_GET is used to store and access last used id and unique ids for each label inside the arrow function. $_GET[0] holds last used id and $_GET[<label>] holds unique id for <label>.

PHP (7.4), 148 bytes

<?=preg_replace_callback('/[@_]\w+(?=([^"]*"[^"]*")*[^"]*$)/',fn($m)=>[':'][$m[0][0]>A].($_GET[$w=substr($m[0],1)]?:$_GET[$w]=++$_GET[0]),$argv[1]);

Try it online!

Define labels with @ and refer to them with _.

Captures any @<label> or _<label> which aren't inside double quotes ("...") and replaces them with a unique number for every unique label, starting from 1. Also adds the : when replacing labels that have @ before them.

PHP's global variable $_GET is used to store and access last used id and unique ids for each label inside the arrow function. $_GET[0] holds last used id and $_GET[<label>] holds unique id for <label>.

PHP (7.4), 148 143 bytes

-5 bytes by stealing RegEx idea from @Arnauld.

<?=preg_replace_callback('/".*?"|([@_]\w+)/',fn($m)=>$m[1]?[':'][$m[0][0]>A].($_GET[$w=substr($m[0],1)]?:$_GET[$w]=++$_GET[0]):$m[0],$argv[1]);

Try it online!

Define labels with @ and refer to them with _.

Captures any @<label> or _<label> which aren't inside double quotes ("...") and replaces them with a unique number for every unique label, starting from 1. Also adds the : when replacing labels that have @ before them.

PHP's global variable $_GET is used to store and access last used id and unique ids for each label inside the arrow function. $_GET[0] holds last used id and $_GET[<label>] holds unique id for <label>.

added 241 characters in body
Source Link
Night2
  • 6k
  • 1
  • 14
  • 46

PHP (7.4), 148 bytes

<?=preg_replace_callback('/[@_]\w+(?=([^"]*"[^"]*")*[^"]*$)/',fn($m)=>[':'][$m[0][0]>A].($_GET[$w=substr($m[0],1)]?:$_GET[$w]=++$_GET[0]),$argv[1]);

Try it online!

Define labels with @ and refer to them with _.

Captures any @<label> or _<label> which aren't inside double quotes ("...") and replaces them with a unique number for every unique label, starting from 1. Also adds the : when replacing labels that have @ before them.

PHP's global variable $_GET is used to store and access last used id and unique ids for each label inside the arrow function. $_GET[0] holds last used id and $_GET[<label>] holds unique id for <label>.

PHP (7.4), 148 bytes

<?=preg_replace_callback('/[@_]\w+(?=([^"]*"[^"]*")*[^"]*$)/',fn($m)=>[':'][$m[0][0]>A].($_GET[$w=substr($m[0],1)]?:$_GET[$w]=++$_GET[0]),$argv[1]);

Try it online!

Define labels with @ and refer to them with _.

PHP (7.4), 148 bytes

<?=preg_replace_callback('/[@_]\w+(?=([^"]*"[^"]*")*[^"]*$)/',fn($m)=>[':'][$m[0][0]>A].($_GET[$w=substr($m[0],1)]?:$_GET[$w]=++$_GET[0]),$argv[1]);

Try it online!

Define labels with @ and refer to them with _.

Captures any @<label> or _<label> which aren't inside double quotes ("...") and replaces them with a unique number for every unique label, starting from 1. Also adds the : when replacing labels that have @ before them.

PHP's global variable $_GET is used to store and access last used id and unique ids for each label inside the arrow function. $_GET[0] holds last used id and $_GET[<label>] holds unique id for <label>.

Source Link
Night2
  • 6k
  • 1
  • 14
  • 46

PHP (7.4), 148 bytes

<?=preg_replace_callback('/[@_]\w+(?=([^"]*"[^"]*")*[^"]*$)/',fn($m)=>[':'][$m[0][0]>A].($_GET[$w=substr($m[0],1)]?:$_GET[$w]=++$_GET[0]),$argv[1]);

Try it online!

Define labels with @ and refer to them with _.