Sublime Forum

Where is "$2"?

#1

In snippet, where is $2 in this substitution?

Transformation: ${1/^(\w)|(?:_(\w))/(?1\u$1:)(?2 \u$2:)/g}
Original: ${1:text_in_snail_case}

Output:
Transformation: Text In Snail Case
Original: text_in_snail_case

0 Likes

#2

You can just count the matching groups ?: means the group does not have a number

  • $0: ^(\w)|(?:_(\w))
  • $1: (\w) in ^(\w), i.e. first word char after start
  • $2: (\w) in (?:_(\w)), i.e. word char after an underscore
3 Likes

#4

/([^%]|%%)*(%.)?.*/
in the above expression,
$0:/([^%]|%%)*(%.)?.*/
$1:([^%]|%%)*
$2:(%.)?
$3:.*
am I right?

0 Likes

#5

Thank you very much.

0 Likes

#6

/ is not part of the expression so it would be $0:([^%]|%%)*(%.)?.*
also the matching groups are creating with parens so $3 would not exists and I am not sure what would be the content of $1, because the * is outside of the paren.

In general I would write something like that with ((?:[^%]|%%)*), i.e. you use ?: to not create a matching group, but create the matching group around the whole expression you want to match.

2 Likes