如何根据某些条件创建正则表达式 [英] how to create regular expression based on some condition

查看:829
本文介绍了如何根据某些条件创建正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我想创建一个正则表达式以根据某些条件查找和替换大写字符.

在字符串中找到一组大写字符的起始大写字母,并将其替换为小写字母,并在起始大写字母之前替换"*".
如果在大写字母之后有任何小写字母,则将大写字母替换为小写字母,并在起始大写字母之前替换"*".

示例:
输入字符串:stackOVERFlow

预期输出:堆栈*溢出*流

我尝试过,但无法使其正常运行.

关于如何创建正则表达式的任何想法吗?
如果要编写更通用的解决方案,请尝试使用C#中的表达式树.基本上,表达式树以树状数据结构表示代码,其中每个节点都是一个表达式.


Hi,
i want to create a regular expression to find and replace uppercase character based on some condition.

find the starting uppercase for a group of uppercase character in a string and replace it lowercase and "*" before the starting uppercase.
If there is any lowercase following the uppercase,replace the uppercase with lowercase and "*" before the starting uppercase.

Example:
input string : stackOVERFlow

expected output : stack*over*flow

i tried but could not get it working perfectly.

Any idea on how to create a regular expression ?
Thanks

解决方案

If you are writing more generic solution, then try out Expression Trees in C#. Basically, expression trees represent code in a tree-like data structure, where each node is an expression.


这篇关于如何根据某些条件创建正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆