Shubham Paramhans
Shubham Paramhans

Reputation: 85

replace regular expression in sublime text

I have application where few labels are written like

ui-label-Display Not Masked

Now I want to replace it by

ui-label-Display_Not_Masked

so i have written search regex by

ui-label-(\w+ )*

This searches all expression but I am not able to create a expression to replace this text as required. I have written one regex

$1_

which replaces

ui-label-Display Not Masked 

by

ui-label-Display Not_Masked 

Upvotes: 1

Views: 2588

Answers (1)

Aran-Fey
Aran-Fey

Reputation: 43296

This cannot be done with a single regex in a single iteration. You have two choices:

  1. Replace (ui-label-\w+) (note the space at the end) with $1_ until it no longer matches anything.
  2. Make a looong regex with as many capture groups as necessary, i.e. (ui-label-\w+) (?:(\w+)(?: (\w+))?)? and replace with $1_$2_$3.

Upvotes: 2

Related Questions