繁体   English   中英

简单的C#正则表达式

[英]Simple C# Regex

我正在尝试从Web服务响应中正则表达式中的字符串中给出的哈希值。 给出的响应格式为:

Write this code down, this is your id for the following tasks: P+3zLI8x1AokfbZ1jXat9g==

You will need to enter the code in each of the following steps.

The next task is somewhat simpler, and demonstrates the process of validating data input to a service.

The next method that has been exposed for you is a method called 'girls'.  
This method takes five parameters, the first four of which are the first names of the members of Girls Aloud, in alphabetical order (a quick search on wikipedia will help out here), and the fifth parameter is your unique id code.  

Create a windows application to send the correct data and the response will be a string with your next set of instructions.`

我感兴趣的哈希是“ id”,id est, "P+3zLI8x1AokfbZ1jXat9g==" 我尝试使用正则表达式,例如"^:\\\\w*=$"但与它不匹配...

有人可以帮我吗?

(而且,对于那些精打细算的人来说,它来自非CS课程中的一个简单的Web服务示例;我正尝试通过正则表达式提取哈希值,而不仅仅是写下来。)

[A-ZA-Z + 0-9] {22} ==

应该起作用,因为哈希值始终是特定长度,并且使用了有限的字符集(无标点符号)。

您发布的正则表达式的最大问题是,您试图将其锚定到行的开头和结尾,这样,如果哈希是该行中唯一的内容,则表达式将匹配。 您实际上不需要这样做。 如果确实需要,可以将此表达式锚定在行的末尾 ,但是不必进行匹配。

也许尝试阅读此文本的第一行,然后像这样拆分它

string hash = stream.ReadLine().Split(":")[1];
tasks:\s(.+)\W

\\ S * ==

这将匹配所有完整的单词,并以'=='结尾。

RegexStudio是您的朋友;)

string resultString = null;
try {
    resultString = Regex.Match(subjectString, "^Write this code down, this is your id for the following tasks: (?<ID>.+)$", RegexOptions.Multiline).Groups["ID"].Value;
} catch (ArgumentException ex) {
    // Syntax error in the regular expression
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM