regex - How to change all title attribute's value in Title Case in sublime text -


i have 500 html files in project casing , quotes (" or ') in <title> attribute vary on pages, see few examples below

<button title="next" id="next"> next</button> <button title="next"> next </buton> <button title=""please go back">check</button>  

i want change title attributes in title case

<button title="next" id="next"> next</button> <button title="next"> next </buton> <button title="please go back">check</button># 

i have tried find , replace - regular expression , case sensitive button enabled

find what: title=(".*")\s
replace with: title="\u$"

but didn't success.please tell me doing wrong?

updated : want remove ' " see #

to further comment, first it's issue of .* being 'greedy' instead of 'lazy', meaning matching as possible (i.e. next"> next</button><button title="next in example).

the quick fix using 'lazy' .* instead, aka .*? (i added ? indicate possible presence of space because there's none in examples):

title=(".*?")\s? 

to improve performance, use negated class:

title=("[^"]+")\s? 

where [^"]+ matches character except ".

and cope different quotes, can use:

title=("[^"]+"|'[^']+')\s? 

which means either "[^"]+" or '[^']+' part within parentheses.


for replace , consecutive quotes issue:

title=(?:"+([^"]+)"+|'+([^']+)'+)\s? 

replace with:

title="\u$1$2" 

the thing last line <button title="please go back">check</button>, if that's not issue...

edit: \g works. use second replace:

(?:(?<=title=")|(?<!^)\g)[^\s"]+\s? 

replace with:

\u$0 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -