i have this string
[111] Test Team +3½-110
and i my expected out is this
team : Test Team,
bet : +3½-110
how can i do that in jquery?
TIA
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.
You wouldn’t use jQuery for this (nor is the “json” tag appropriate), you’d use standard JS string manipulation functions (with or without regex).
I’ll assume the rule for splitting up your string is to ignore any leading value in square brackets, then take everything up to the
+as the team name and everything after the+(including the+itself) as the bet. If there’s more than one+then all but the last will be considered part of the team name.Demo: http://jsfiddle.net/LKJjw/
In my regex:
…optionally matches at the beginning of the string a
[followed by zero or more non-]characters followed by]and a space. Then:…matches the team name – one or more of any character. Then:
…matches a space followed by a
+, followed by one or more non-+characters at the end of the string.