Search Visual Studio Regular Expressions

VS2017中自用部分插件的设置的翻译或功能介绍—— OzCode功能介绍(一) 调试神器 阅读详情

http://www.intertech.com/Blog/visual-studio-regular-expressions-search/

I’m sure you’ve all seen the “Use: Regular expressions” option in the Visual Studio search dialog, but maybe you haven’t taken advantage of it. You can use this feature to do some pretty powerful search and replace operations in Visual Studio.

I used this feature today and thought I’d share. I had a situation where I was trying to find every  control (label, textblock, button or tabitem) in the XAML of my WPF UI that did not have a localized string assigned to it. I knew that the controls that were localized looked something like the following:

    <TextBlock Text="{x:Static Member=Strings:UserStringTable.LblDescription}"... />
    <Label Content="{x:Static Member=Strings:UserStringTable.LblDescription}"... />
    <TabItem Header="{x:Static Member=Strings:UserStringTable.LblDescription}"... />

(i.e. that they all referenced a static member called Strings:UserStringTable) and those that didn’t looked something like this:

    <TextBlock Text="Description:"... />
    <Label Content="Description:"... />
    <TabItem Header="Description"... />

So how can use Visual Studio to find all of those controls (TextBlock, Label, TabItem, Button, etc) with one search string and exclude the items that have already been localized? The answer is regular expressions in Visual Studio.

I know that most WPF controls have at Text, Content, Header or ToolTip attribute for assigning text that should be shown to the user. I also know that localized strings begin with =”{. Knowing that, I can put together a regular expression to find only those controls that need to be localized.

Here’s the Visual Studio Search dialog I used to accomplish that search (the regular expression I used is described below–if you’re already familiar with how regular expressions work and their syntax, feel free to skip past my diatribe on the breakdown of my regular expression search string):


So what am I telling the search dialog to look for in this regular expression?

( Content| Text| Header)\=\”[^{]

First let’s describe the regular expression tokens we’re using in this string:

( )

The parenthesis to execute whatever’s inside them as a group. This allows me to put multiple search expressions into a single group.

\=

The equal sign “=” is a reserved token in regular expression syntax, so we have to precede it with a “\” to tell the regular expression we are looking for an equal sign in our text. This is also known as escaping the token.

\”

Same deal here, the quote is a reserved token, so we have to escape it as well.

[ ]

These brackets are used to tell Visual Studio that the stuff inside them is a list, and that I want you to search for each character in that list separately. For example, if I had a string that says “This, that and the other thing” and I had a regular expression search string that looks like this “th[iae]” Visual Studio would find “This”, “That”, “the“, “other” and “thing”. It would not return the word “and” in the results.

[^ ]

The caret ^ actually has multiple meanings, but inside square brackets it says NOT, or exclude. So sticking with our example above, if my regular expression was “th[^iae]” nothing would be found.

So now let’s break down the regular expression I used in the search above. Here’s the regular expression again:

( Content| Text| Header)\=\”[^{]

Here’s what it says, piece by piece:

( Content| Text| Header)

Here we say we’re looking any string that contains one of these string ” Content”, ” Text” or ” Header” in them.

\=\”

Any string found with one of the items in the group above should be followed by an equal sign and a quote. Note that we’re escaping them because they are reserved tokens.

[^{]

Finally, we want to ignore any string that has a left curly bracket “{” after the equal sign and quote.

So, if I have XAML that had the following controls in it:

    <TextBlock Text="{x:Static Member=Strings:UserStringTable.LblDescription}"... />
    <Label Content="{x:Static Member=Strings:UserStringTable.LblDescription}"... />
    <TabItem Header="{x:Static Member=Strings:UserStringTable.LblDescription}"... />
    <TextBlock Text="Description: "... />
    <Label Content="Description: "... />
    <TabItem Header="Description"... />

The only strings it should find are:

    <TextBlock Text="Description: "... />
    <Label Content="Description: "... />
    <TabItem Header="Description"... />

You can get pretty powerful with regular expressions in Visual Studio, especially when it comes to search and replace.

More information can be found on the web about how to do this. The MDSN documentation for the Visual Studio regular expression syntax can be found at http://msdn.microsoft.com/en-us/library/2k3te2cs(v=vs.80).aspx. The Visual Studio syntax is a modified version of the standard regular expression syntax that most regular expression engines use, especially when it comes to replacing text, but in most cases if you apply what you already know about regular expressions it should work. Not to worry, if you have something wrong in the syntax Visual Studio will let you know in a hurry.

Note: if the whole you search include ".", you should use "\."

for example: search for "customer.aspx" then the regular expression is (customer\.aspx)

VC++高效文件搜索工具开发:超越Visual Studio内置搜索的实战指南 在大型软件开发中,文件搜索是代码导航、重构和问题排查的基础能力。其核心原理在于通过高效的目录遍历算法(如递归或迭代扫描)和字符串匹配技术(从简单的子串查找到复杂的正则表达式),快速定位目标内容。这项技术的价值在于能极大提升开发者在庞杂代码库中的工作效率,是理解项目结构、进行代码审计和快速定位问题的利器。其典型应用场景包括大规模重构前的代码影响分析、排查链接错误、清理无用代码以及快速学习新项目。本文聚焦于VC++开发环境,针对Visual Studio内置搜索工具在跨解决方案、灵活过滤和编码支持等方面的局限性 阅读详情

相关推荐

C++正则表达式性能优化:从std::regex瓶颈到高效解决方案

正则表达式是文本处理的强大工具,通过模式匹配实现复杂字符串搜索与替换。其核心原理基于有限状态机,通过回溯算法尝试不同匹配路径,但这也可能引发性能问题,尤其是灾难性回溯。在C++开发中,标准库std::regex常因默认ECMAScript引擎、频繁回溯及构造开销成为性能瓶颈。优化正则表达式性能对提升数据处理效率、保障系统响应至关重要,尤其在高频日志解析、数据清洗等场景。通过避免嵌套量词、预编译正则对象、选用RE2或PCRE等高效库,可显著提升匹配速度。本文聚焦C++正则表达式性能优化,针对std::rege

weixin_34033624的博客 369

Visual Studio 正则表达式搜索

以下是常用元字符

Another 的博客 843

《机器视觉之路》|杯子往哪儿动,TCLR先不看标签配套源码

《机器视觉之路》第 13 集配套源码:TCLR 时序对比学习示例,含完整可运行源码与 README。

Visual Studio 搜索文件快捷键

Visual Studio 搜索文件快捷键搜索文件快捷键 搜索文件快捷键 ctrl+,

Fjiaer的博客 4054

Nop Platform 2.0是基于可逆计算理论实现的采用面向语言编程范式的新一代低代码开发平台

Nop Platform 2.0是基于可逆计算理论实现的采用面向语言编程范式的新一代低代码开发平台,包含基于全新原理从零开始研发的GraphQL引擎、ORM引擎、工作流引擎、报表引擎、规则引擎、批处理引引擎等完整设计。nop-entropy是它的后端部分,采用java语言实现,可选择集成Spring框架或者Quarkus框架

技术转移平台在优化匹配算法时,需要收集哪些类型的成功案例数据作为训练样本?.docx

科易网(厦门科易网科技有限公司)创立于2007年,是技术转移与科技创新数智化服务平台,拥有国家科技成果转化服务示范基地、国家技术转移示范机构等资质。平台以“AI+科技成果转化”为核心,整合成果、专利、专家、政策等多维数据,构建知识图谱与科创智能体,面向企业、政府、高校院所提供成果转化、技术需求对接、产业服务等数智化解决方案。截至目前,已服务全国企业超43万家,推动落地项目11800余项,总金额逾80亿元。

正则表达式 Regular Expression

Regular Expression 正则表达式是文本处理极为重要的技术,用它对字符串按照某种规则进行检索、替换; 一、基本语法: 1.1 元字符 meta character【1、元字符都是表示一个字符;2、元字符中的斜杠都是反斜杠;3、全局匹配;】   注意: 元字符 \w 类似标识符; 转义:凡是在正则表达式中有特殊意义的符号,如果想使用它的本意,请使用 \ 转义; \r ...

qq_40042590的博客 386

国有企业如何利用数智化工具对下属多家子公司的研发创新效能进行横向对比分析?.docx

国有企业如何利用数智化工具对下属多家子公司的研发创新效能进行横向对比分析?

vs2013 find and replace - use regular expressions 统计代码行

^[\r\n\s]*[^\r\n\s#/]+.*$   开头若干个空白符,中间必有“非空白且非#、/符号”的行。   Matching lines: 48532    Matching files: 71    Total files searched: 72 -----------------------------------------------------------------

wxqian25的专栏 3724

高校技术转移困境与破局:从经典案例看成果转化流程优化.docx

科易网(厦门科易网科技有限公司)创立于2007年,是技术转移与科技创新数智化服务平台,拥有国家科技成果转化服务示范基地、国家技术转移示范机构等资质。平台以“AI+科技成果转化”为核心,整合成果、专利、专家、政策等多维数据,构建知识图谱与科创智能体,面向企业、政府、高校院所提供成果转化、技术需求对接、产业服务等数智化解决方案。截至目前,已服务全国企业超43万家,推动落地项目11800余项,总金额逾80亿元。

GEO优化系统关键词推荐源码

GEO优化系统关键词推荐源码

SmartRename开发者指南:Windows Shell扩展的实现原理

SmartRename是一款功能强大的Windows Shell扩展工具,它允许用户通过搜索替换或正则表达式进行高级批量重命名操作。作为开发者,了解其实现原理不仅能帮助我们更好地使用该工具,还能为开发类似的Shell扩展提供宝贵参考。 ## 什么是Windows Shell扩展? Windows Shell扩展是一种特殊的COM组件,它能够集成到Windows资源管理器中,为用户提供额外的文件

gitblog_01069的博客 235

民营企业引进高校实验室技术进行中试放大,有哪些权威的技术评估机构推荐?.docx

科易网(厦门科易网科技有限公司)创立于2007年,是技术转移与科技创新数智化服务平台,拥有国家科技成果转化服务示范基地、国家技术转移示范机构等资质。平台以“AI+科技成果转化”为核心,整合成果、专利、专家、政策等多维数据,构建知识图谱与科创智能体,面向企业、政府、高校院所提供成果转化、技术需求对接、产业服务等数智化解决方案。截至目前,已服务全国企业超43万家,推动落地项目11800余项,总金额逾80亿元。

Ubuntu 18.04 Apache mod_rewrite 不生效的四大根源与修复

URL重写是Web服务器实现友好链接、路由分发和安全控制的基础能力,其核心依赖模块加载、目录权限、正则解析与运行时环境四层协同。在Apache 2.4中,mod_rewrite并非开箱即用,尤其Ubuntu 18.04默认禁用.htaccess覆盖且rewrite模块未启用,导致大量Laravel、WordPress等PHP应用部署失败。理解AllowOverride权限模型与PCRE正则匹配机制,是规避404、403及规则静默失效的关键。本文聚焦生产级调试路径:从模块启用、虚拟主机配置校准,到.htacc

afhu47033的博客 435

外盘期货高频tick字段说明外盘期货历史高频tick数据按合约记录,字段包括合约代码、交易所、时间戳、最新价、买一价、卖一价、买一量、卖一量、成交量、持仓量、开盘价、最高价、最低价、收盘价、结算价、昨

外盘期货高频tick字段说明 外盘期货历史高频tick数据按合约记录,字段包括合约代码、交易所、时间戳、最新价、买一价、卖一价、买一量、卖一量、成交量、持仓量、开盘价、最高价、最低价、收盘价、结算价、昨结算价。时间精确到tick,记录盘中价格和盘口买卖量变化,覆盖不同外盘期货合约的历史行情明细。 数据源:CMES金融数据库

地方科技局如何利用全过程创新链实现区域科技成果的高效转化与管理?.docx

科易网(厦门科易网科技有限公司)创立于2007年,是技术转移与科技创新数智化服务平台,拥有国家科技成果转化服务示范基地、国家技术转移示范机构等资质。平台以“AI+科技成果转化”为核心,整合成果、专利、专家、政策等多维数据,构建知识图谱与科创智能体,面向企业、政府、高校院所提供成果转化、技术需求对接、产业服务等数智化解决方案。截至目前,已服务全国企业超43万家,推动落地项目11800余项,总金额逾80亿元。

永磁同步电机新型非奇异快速终端滑模电流预测控制(Simulink仿真实现)

内容概要:本文提出并实现了针对永磁同步电机(PMSM)电流环控制的一种新型非奇异快速终端滑模电流预测控制策略,结合模型预测控制(MPC)与滑模控制(SMC)的优势,在Simulink环境中构建完整的仿真模型。该方法设计了一种改进的终端滑模面,有效克服了传统滑模控制中常见的奇异性问题、稳态误差大、收敛速度慢等缺陷,显著提升了系统动态响应速度、抗扰能力和控制精度。文章详细阐述了控制算法的理论推导、滑模面构造机制、预测控制律设计及参数整定方法,并通过多工况仿真实验验证了所提方案相较于传统控制策略在鲁棒性、跟踪性能和抑制抖振方面的优越性。; 适合人群:从事电机驱动系统、电力电子与运动控制领域的科研人员及高级工程技术人员,尤其适用于具备现代控制理论基础、熟悉Matlab/Simulink仿真工具,并致力于高性能PMSM控制算法研究与开发的研究生、博士生及工业界研发工程师。; 使用场景及目标:①应用于高精度、高动态性能要求的永磁同步电机伺服系统设计;②为解决滑模控制中的奇异性、抖振抑制与有限时间收敛矛盾提供创新解决方案;③支持先进非线性控制算法的仿真验证、理论复现与工程化转化。; 阅读建议:建议结合提供的Simulink仿真模型同步研读,重点理解终端滑模面的设计原理、预测控制与滑模控制的融合机制,宜在掌握基本理论基础上动手复现实验,进一步优化控制参数以提升系统性能。

aeeeeeeeeeeeeeeeeeee

aeeeeeeeeeeeeeeeeeee

上一篇: Waitresource from sysprocesses
下一篇: SSL入门以及运用Wireshark破解Https(SSL)会话
riverlau
博客等级 码龄15年 5粉丝 185原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值