0

I have an application that the user may specify a prompt... That may be in Regex type or in string type.

The user have a checkbox, if he check the checkbox the prompt var will be a string type if not check will be a Regex.

Then I need to be able to reference that later in the program.

so I am wondering how to define that...

Currently I have the following :

textbox1.text = "\[.*@.*\][\$|\#]"  < --- that is a Regex 

or it could be something like :

textbox1.text = "#$"                < --- that would be a regular string...

and somewhere in my apps I need to use that info...

string userPrompt:
string rootPrompt;

if (userPromptIsText)
{
    userPrompt = textBoxp4RegPrompt.Text.Trim();
}
else
{
    // here how do I say that userprompt is a regex type?
} 
4
  • you have not posted all the relevant code. We would need to see your HTML of the form that has your checkbox, and text field. Commented Apr 8, 2013 at 15:49
  • You already have the value from the checkbox. What more do you need? Commented Apr 8, 2013 at 16:06
  • @Patrick I need to be able to take the textbox1.text value and use it as a regex, but later in the apps. So when I need to use it I have to be able to either use it as a string or as a regex... but not sure if possible I would like to maintain the same name i.e userPrompt... no matter what type it is... Commented Apr 8, 2013 at 16:10
  • 1
    Is there something preventing you from passing a boolean from the checkbox along with userPrompt? Commented Apr 8, 2013 at 16:11

1 Answer 1

1

It seems like you should store the entered regular expression not in the string variable "userPrompt", but rather in a Regex so you can use it:

System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(textBoxp4RegPrompt.Text.Trim());

And then you can use the regex variable for performing matches:

System.Text.RegularExpressions.Match results = regex.Match(stringToTest);  
MessageBox.Show(results.Groups[0].Value);
MessageBox.Show(results.Groups[1].Value); 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.