Simple C # Regex

I am trying to re-expose a hash specified in a string from a web service response. The answer is in the format:

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.`

Hash that interests me is "id", id est, "P+3zLI8x1AokfbZ1jXat9g=="

. I tried using regex for example "^:\\w*=$"

, but it didn't match it ...

Can anyone help me?

(And for those interested, this is from a simple webservice example from a non-cs course, I'm trying to extract the hash through a regex, not just write it down.)

0


a source to share


5 answers


\ S * ==

This matches all whole words at the end of the line ending with '=='.



RegexStudio is your friend;)

+1


a source


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

Should work as hashes are always of a certain length and use a limited character set (no punctuation).



The biggest problem with regex you posted is that you were trying to bind it to the front and end of the line so that the expression matches if the hash is the only one on that line. You really don't need it. If you really want to, you can only bind this expression to the end of the line, but you don't have to get a match.

+1


a source


Maybe try to read the first line of that text and then split it like this

string hash = stream.ReadLine().Split(":")[1];

      

+1


a source


tasks:\s(.+)\W

      

+1


a source


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
}

      

0


a source







All Articles