什么是正则表达式&如何在C#中使用正则表达式? [英] What is Regex & How to use Regular Expressions with C#?

查看:100
本文介绍了什么是正则表达式&如何在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[^]

Quote:

我们如何在我们的程序中实现这一点?

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


这篇关于什么是正则表达式&amp;如何在C#中使用正则表达式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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