chriz
chriz

Reputation: 1345

regex for checking the format of a string

regex always making me struggle.. what i want here is i have to check whether a string is in the given format in js.

{word}/numbers  operator {word}/numbers operator {word}/numbers 

Eg : {VAT}+50+{tax}-20 

Note :

and it will be more appreciated if someone suggest any website or something that i can get easy with regex in future.. thanku :)

Upvotes: 0

Views: 73

Answers (2)

sshashank124
sshashank124

Reputation: 32199

The following regex also works for any length:

^((\{\[a-zA-Z0-9]\}|\d+)([+\-\*\/]|$))+$

Demo: http://regex101.com/r/hV1hL1

Upvotes: 1

hsz
hsz

Reputation: 152276

Just try with following regex:

/^((?:{[a-z]+})|\d+)([+*/-]((?:{[a-z]+})|\d+))*$/i.test("{VAT}+50+{tax}-20")

In this regex are included following operators: +*/-

Upvotes: 4

Related Questions