English 中文(简体)
1. 定期致电用户名
原标题:Regular Expression to get username from messages
  • 时间:2010-05-20 08:07:29
  •  标签:
  • c#
  • regex

我提出我的申请将获得的两种可能的细微投入,如果与以下两条插图相匹配,我需要加以分类,以恢复:

"User * has logged out"
"User * has joined"

我不喜欢reg,而只是想说明如何实现上述目标。

任何帮助都是巨大的!

最佳回答

假设你意欲将<代码>*字面上作为星号加以匹配,那么,你需要先用<代码><>/代码>填写。

@"> 用户* (略微)

如果通过<代码>*,你指“任何用户名称”,则代之以您为验证用户名称而使用的密码,或因缺乏任何更好的信息,你总是只能使用<代码>*。

<代码>(挂号:建筑称为“硬化”。 周围的括号除在本案中强制规定交替优先外,还把载于第1组的“座标”()”或“joined”),视其不同之处而定。

如果你不需要区分这两种事件,那么你实际上就不需要这种扼杀,而且你可以使用一个没有捕获的组群(<条码>(?: 缩略语),以便稍微提高业绩。

^ and $ are what are打脚石, which they they have been used and end of the string. 适当将这些根基置于模式中,可确保它与整个投入结构相匹配,而不仅仅是一个子体。

regular-expressions.info Links

问题回答

* 假定为用户名称:

"User .+ has (joined|logged out)"

或者也许像这种情况(用户名称可能需要更多的特性选择):

"User [A-Za-z0-1_]+ has (joined|logged out)"




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...