Question

Write a regular expression for all unsigned numbers. They are strings such as 5280, 39.37, 499E3,...

Write a regular expression for all unsigned numbers. They are strings such as 5280, 39.37, 499E3, 63.36E4, 1.894E-3, 2.3478E+11. You are not allowed to have a naked decimal point. For example the number 5. or .5 is not allowed, must use 5.0 and 0.5. The E is for exponent, essentially scientific notation. Give the transition diagram as well.  

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The regular expression is given as:

^\d+(\.\d{1,2})?$
\d+(\.\d{1,2})?

It allows all of your cases and nothing else.

  • ? after things makes them optional
  • \d matches any digit
  • + after things means there need to be one or more of them
  • . matches all characters, therefore it is escaped here to match the literal dot
Add a comment
Know the answer?
Add Answer to:
Write a regular expression for all unsigned numbers. They are strings such as 5280, 39.37, 499E3,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT