受正则表达式的解析字母顺序影响 [英] affected by the order of letters of paresis using Regex

查看:68
本文介绍了受正则表达式的解析字母顺序影响的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在尝试制作正则表达式模式.
因此,用户输入带字母的字符串. ("bcade")
什么是Regex模式,使此输入看起来像-> abcde?
感谢您的回答:)

Hi,
I am trying to make Regex pattern.
so, the user input string with letters. ("bcade")
what is the Regex pattern, to make this input look like -> abcde?
Thanks for answers :)

推荐答案

没有明智的正则表达式可以做到这一点-这是排序例程的工作.
最简单的方法是将字符串转换为字符数组,对其进行排序,然后再次转换回字符串.

There is no sensible regex which will do that - it is a job for a sort routine.
The easiest way is to convert the string to a character array, sort it, and convert back to a string again.

string s = "bcade";
char[] chars = s.ToCharArray();
Array.Sort(chars);
s = new String(chars);
Console.WriteLine(s);


这篇关于受正则表达式的解析字母顺序影响的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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