I have a vast array list like below
$data= [
'user_name' => 's',
'user_place' => 'a',
'address_list_code' => 's',
'block_number' => 3,
];
so I want to replace the key string with all uppercase.I know to convert selected text to uppercase using vs code shortcut Ctl Alt u
and it works.
But I want to select only all keys in between a single quote and make it uppercase so the expected output is
[
'USER_NAME' => 's',
'USER_PLACE' => 'a',
'ADDRESS_LIST_CODE' => 's',
'BLOCK_NUMBER' => 3,
];
Even I tried this extension but not suceded to select all text in between single quotes
CodePudding user response:
Check out this fiddle : https://jsfiddle.net/m82ycfxw/
I made a normal JS code to convert the desired text to upper case.
This might be a temporary thing but I hope this will work for you.
let str = `
$data= [
'user_name' => 's',
'user_place' => 'a',
'address_list_code' => 's',
'block_number' => 3,
]
`;
var regex = /'[a-z_] ' =>/g;
str = str.replace(regex, foundText => {
return foundText.toUpperCase();
});
console.log(str);
Just change the str
variable. Put all your complete data object inside backticks (` `)and run the code.
CodePudding user response:
The extension Select By could help.
- Place cursors at the start of the lines where you want to Uppercase text
- with MoveBy: Move cursors based on regex move to the next
'
- with SelectBy: Mark positions of cursors
- with MoveBy: Move cursors based on regex move to the next
'
- with SelectBy: Mark positions of cursors (create selections)
- execute: Transform to Uppercase
Esc
to exit multi Cursor
CodePudding user response:
Sure, you can do this natively:
- In
settings.json
, temporarily remove_
as a word separators (e.g."editor.wordSeparators": "!@#$%^&*()-= [{]}\\|;:'\",.<>/?,
) (Notice no_
) . - Place cursors at beginnings of all desired lines.
- Right arrow to move all cursors within the quotes.
- Execute command
expand selection
. Since you turned off_
as a word delimiter, this will expand to fill the quotes; otherwise, all the keys would need to have the same number of words for this to work. - Execute
upper case
. - In
settings.json
re-add_
to word separators.
CodePudding user response:
Easy with Find and Replace. See regex101 demo
Find: (^\s ')([^']*)'
Replace: $1\U$2'
The \U
will uppercase the following capture group $2
.
Starting the find at the beginning of the line with ^
makes it easy to target just the "keys" (the first '
-delimmited strings) and not the other following strings.