I am looking for a regular expression in C# to match any of these strings: “+99.99”, “-99.99”, “99.99”. The same regular expression should not match the string “+-99.99”. Can any one please suggest an answer.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The following worked for me:
Yielded:
Explanation:
^will instruct the regex engine to start matching from the beginning of the string,(\\+|-)denotes a+or-character. The+is a special character in regex syntax and thus needs to be escaped. The OR operator is denoted by the|character.The
?denotes that the+or-character may or may not be there (it will match 0 or 1 instances of whatever preceeds it).99\\.99denotes the string99.99. The.is also a special character in regex syntax and thus needs to be escaped. The$character will instruct the regex engine to stop matching at the end of the string.