Note that there are some explanatory texts on larger screens.

plurals
  1. POVariable number of matches / back references in Regex?
    primarykey
    data
    text
    <p>I spent some time recently converting some SCSS code to Stylus, and one of my regex steps was to strip out the <code>$</code> character in variable names, while formatting those names to camelCase rather than hyphenated-case. </p> <p>For example, <code>$long-hyphenated-variable-name: value;</code> became <code>longHyphenatedVariableName = value;</code> but parameter names like <code>text-size</code> did not become <code>textSize</code>.</p> <p>anyway, my Regex skills are pretty limited, so I could only figure out how to do it as a series of passes, looking first for variable names that might have as much as 6 parts (5 hyphens) and then for shorter ones on subsequent passes and passing each part of the string as a separate backreference so I could capitalize the first letter. But I wondered if there was a better way to do it: i.e. is there a way to get a variable number of sub-string matches within the string and supply back-references in accordance with how many you got? I just couldn't find any information on this.</p> <p>This is my code, in six steps, which I'd like to condense to one if it's possible (I'm thinking of writing a multi-step regex routine that can convert SCSS to Stylus for future use). In each case the search expression is followed by the replacement expression:</p> <pre><code>\$(\S*?)\-(\S*?)\-(\S*?)\-(\S*?)\-(\S*?)\-(.) $1\u$2\u$3\u$4\u$5\u$6 \$(\S*?)\-(\S*?)\-(\S*?)\-(\S*?)\-(.) $1\u$2\u$3\u$4\u$5 \$(\S*?)\-(\S*?)\-(\S*?)\-(.) $1\u$2\u$3\u$4 \$(\S*?)\-(\S*?)\-(.) $1\u$2\u$3 \$(\S*?)\-(.) $1\u$2 \$(.) $1 </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload