Sudhir Pawar

Greenhorn

Posts: 25

posted 4 years ago

- 1

I want to make regular expression to match any arithmetic expression which is in the form of

number of any digits

e.g 151

single operator from + - * /

number of any digits

e.g 151

e.g 151+151

I write folllowing but it wont work please help me to correct it.

RegExp = /([0-9])+([-|+|*])+([0-9])/;

number of any digits

e.g 151

single operator from + - * /

number of any digits

e.g 151

e.g 151+151

I write folllowing but it wont work please help me to correct it.

RegExp = /([0-9])+([-|+|*])+([0-9])/;

posted 4 years ago

It's always a good idea when working out regular expressions to:

(a) Work out what you want (which you've explained very well, which is why I gave you a +1).

(b) Work out what you DON'T want (which you haven't).

For example: You haven't explained:

1. Is a number

2. Can there be spaces between the "numbers" and the operator?

3. Can there be more than one operator - ie: can an operator be followed by another operator?

I think if you answer those questions, you'll be closer to a solution, because you plainly have a grasp of the general syntax.

Winston

Sudhir Pawar wrote:I want to make regular expression to match any arithmetic expression which is in the form of...

It's always a good idea when working out regular expressions to:

(a) Work out what you want (which you've explained very well, which is why I gave you a +1).

(b) Work out what you DON'T want (which you haven't).

For example: You haven't explained:

1. Is a number

*without*an operator correct?

2. Can there be spaces between the "numbers" and the operator?

3. Can there be more than one operator - ie: can an operator be followed by another operator?

I think if you answer those questions, you'll be closer to a solution, because you plainly have a grasp of the general syntax.

Winston

"Leadership is nature's way of removing morons from the productive flow" - Dogbert

Articles by Winston can be found here

Sudhir Pawar

Greenhorn

Posts: 25

posted 4 years ago

Questions

1. Is a number without an operator correct?

2. Can there be spaces between the "numbers" and the operator?

3. Can there be more than one operator - ie: can an operator be followed by another operator?

Answers

1. Number is always like following number means non negative no.

eg. 21

2. No space matching.

3. No only single operator has to be match from + - / * in between two numbers

1. Is a number without an operator correct?

2. Can there be spaces between the "numbers" and the operator?

3. Can there be more than one operator - ie: can an operator be followed by another operator?

Answers

1. Number is always like following number means non negative no.

eg. 21

2. No space matching.

3. No only single operator has to be match from + - / * in between two numbers

posted 4 years ago

- 1

So, the followings are valid

a) 151

b) 151+151

which yours didn't handle the first case

yours actually formed by 3 parts, could you explain what they are.

By the time you explain to others and yourself, you should find the mistakes.

a) 151

b) 151+151

which yours didn't handle the first case

yours actually formed by 3 parts, could you explain what they are.

By the time you explain to others and yourself, you should find the mistakes.

Sudhir Pawar

Greenhorn

Posts: 25

posted 4 years ago

Could you explain the regular expression you have written part by part ?

I saw 3 pairs of brackets "(" and ")", I assume there are 3 parts, right ?

Sudhir Pawar wrote:b)151+151

is valid one as per my expectations about regular expression

I want regular expression that can match integer_numberOperatorintegerNumber

eg. 456*45

Could you explain the regular expression you have written part by part ?

I saw 3 pairs of brackets "(" and ")", I assume there are 3 parts, right ?