Replace with wildcards

c#, regex

Solution

You can do this

string ns= Regex.Replace(yourString,"Read\s+(.*?)(?:\s|$)","$1 = MessageBox.Show");

`\s+` matches 1 to many space characters

`(.*?)(?:\s|$)` matches 0 to many characters till the first space (i.e `\s`) or till the end of the string is reached(i.e `$`)

`$1` represents the first captured group i.e `(.*?)`

Problem

I need some advice. Suppose I have the following string: `Read Variable` I want to find all pieces of text like this in a string and make all of them like the following:`Variable = MessageBox.Show`. So as aditional examples: ``` "Read Dog" --> "Dog = MessageBox.Show" "Read Cat" --> "Cat = MessageBox.Show" ``` Can you help me? I need a fast advice using RegEx in C#. I think it is a job involving wildcards, but I do not know how to use them very well... Also, I need this for a school project tomorrow... Thanks! Edit: This is what I have done so far and it does not work: `Regex.Replace(String, "Read ", " = Messagebox.Show")`.

Original source