VS代码选择引号之间的文本

发布于 2025-02-11 03:41:09 字数 525 浏览 5 评论 0原文

我有一个像下面的庞大数组列表

$data= [
        'user_name' => 's',
        'user_place' => 'a',
        'address_list_code' => 's',
        'block_number' => 3,
];

,因此我想用所有大写替换键字符串。我知道使用VS代码快捷方式将选定的文本转换为大写ctl+alt+alt+alt+alt+u,并且它起作用。 但是我只想在单个报价之间选择所有键,然后使其大写,所以预期的输出是

[
        'USER_NAME' => 's',
        'USER_PLACE' => 'a',
        'ADDRESS_LIST_CODE' => 's',
        'BLOCK_NUMBER' => 3,
];

我尝试了此扩展名,但也没有吸取单个引号之间的所有文本

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

https://marketplace.visualstudio.com/items?itemName=dbankier.vscode-quick-select&ssr=false#version-history

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

尤怨 2025-02-18 03:41:09

查看此小提琴: https://jsfiddle.net/m82ycfxw/m82ycfxw/

我制作了一个普通的JS代码,将所需的文本转换为上情况。

这可能是暂时的事情,但我希望这对您有用。

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);

只需更改str变量即可。将所有完整的数据对象放入Backticks(````)中,然后运行代码。

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.

ㄖ落Θ余辉 2025-02-18 03:41:09

扩展名 select 可以帮助您。

  • 的线路上的文本的开始,
  • 将光标放置在您想要使用 moveby:基于正则> Move Cursors 移动光标移动到下一个'
  • 请使用 selectby:mark光标
  • 带有 moveby:基于正则>的移动光标移动到下一个'
  • 带有 selectby:光标的标记位置(创建选择)
  • 执行:转换为大写
  • ESC退出多光标

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
以为你会在 2025-02-18 03:41:09

当然,您可以本地进行此操作:

  1. settings.json中,暂时删除_作为单词分隔符(例如“ editor.wordseparator”:“!@#$ $ %^&*() - =+[{]} \\ |;:'\“,。
  2. 将光标放在所有所需线的开端。
  3. 正确的箭头将所有光标移动在引号中。
  4. Execute命令展开选择。由于您将_作为单词定界符关闭,因此将扩展以填充引号。否则,所有的键都需要具有相同数量的单词才能使此工作起作用。
  5. 执行上情况
  6. 设置中。

Sure, you can do this natively:

  1. In settings.json, temporarily remove _ as a word separators (e.g. "editor.wordSeparators": "!@#$%^&*()-=+[{]}\\|;:'\",.<>/?,) (Notice no _)
    .
  2. Place cursors at beginnings of all desired lines.
  3. Right arrow to move all cursors within the quotes.
  4. 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.
  5. Execute upper case.
  6. In settings.json re-add _ to word separators.
洒一地阳光 2025-02-18 03:41:09

轻松使用查找和替换。参见 regex101 demo

find:(^\ s+')(^\ s+')([^'')* )'
替换:$ 1 \ u $ 2'

\ u将大写以下捕获组$ 2

使用^在行开头启动查找,使得仅针对“键”(第一个' -delimmited字符串),而不是其他以下字符串。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文