regexsublimetextsublimetext3

Regex backreference not returning anything?


I'm new to regex, so please, bear with me.

I'm trying to replace everything that says col-md-(\w+) with col-md-(\w+) col-lg-(\w+) in Sublime Text 3.

However, when I use the line col-md-\1 col-lg-\1, it just turns into col-md- col-xs-

What am I doing wrong?

Thanks!

Update: Per request, I am showing the input/output:

...and when I replace all


Solution

  • Remove your lookahead and it will work :

    Find What:    col-md-(\w+)
    Replace With: col-xs-$1 col-sm-$1 col-md-$1 col-lg-$1
    

    Or use $2 instead of $1, as you've got a catching group inside this lookahead:

    Find What:    (?!col-md-(\w+) )col-md-(\w+)
    Replace With: col-xs-$2 col-sm-$2 col-md-$2 col-lg-$2