什么是正则表达式&如何在C#中使用正则表达式? [英] What is Regex & How to use Regular Expressions with C#?
问题描述
在dotnet中使用正则表达式有什么用?我们如何在程序中实现它?
What is the use of regex in dotnet and how can we implement this in our program?
推荐答案
正则表达式有什么用?
看看这里:
http://en.wikipedia.org/wiki/Regular_expression#Uses [ ^ ]
http://blog.stevenlevithan.com/archives/10-reasons-to-learn-and-use-regular-expressions [ ^ ]
Have a look here:
http://en.wikipedia.org/wiki/Regular_expression#Uses[^]
http://blog.stevenlevithan.com/archives/10-reasons-to-learn-and-use-regular-expressions[^]
我们如何在我们的程序中实现这一点?
how can we implement this in our program?
看看这里:
30分钟正则表达式教程 [ ^ ]
http://www.tutorialspoint。 com / csharp / csharp_regular_expressions.htm [ ^ ]
http://msdn.microsoft.com /en-us/library/system.text.regularexpressions.regex.aspx [ ^ ]
Have a look here:
The 30 Minute Regex Tutorial[^]
http://www.tutorialspoint.com/csharp/csharp_regular_expressions.htm[^]
http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex.aspx[^]
正则表达式(或正则表达式)是一种处理文本和执行varie的方法对它们进行模式匹配的过程。
例如,编写一个应用程序来重命名所有MP3文件,使其具有MY MUSIC前缀:
Regexes (or Regular Expressions) are a way to process text and perform a variety of pattern matching processes on them.
And example would be to write an application to rename all your MP3 files to have a "MY MUSIC" prefix:
public static Regex regex = new Regex(
"^(?<!MYMUSIC)(.*\\.MP3)
,
RegexOptions.IgnoreCase
| RegexOptions.Multiline
| RegexOptions.Singleline
| RegexOptions.IgnorePatternWhitespace
| RegexOptions.Compiled
);
// 这是替换字符串
public static string regexReplace =
MYMUSIC
", RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled ); // This is the replacement string public static string regexReplace = "MYMUSIC
这篇关于什么是正则表达式&如何在C#中使用正则表达式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!