It should be very easy, maybe use a regex, but I think that there is an easy-fast way. At present I do this work using some partitions, but it definitely looks like a bad method.
Example string:
On June 9, 2009. Tagged:
What do I need to do that date (June 09, 2009) has been changed to three strings (June, 09, 2009). Obviously this date may vary in things like May 25, 2011. I am using two external strings which will be continuously ("on" and "tagged") and the search based on them is the best method. The month will always be three letters.
What would be a better way of doing this via javascript?
Thank you!
You can use it substring command, but changing the source data to a regex simple And will be less prone.
You can use this regex:
var input = "Tagged on June 09, 2009:"; Var date = input.match (/ ([a-zA-Z] {3}) (\ d {1,2}), (\ d {4}) /); // date = ["June 09, 2009", "June", "09", "200 9"]; Var simpledate = date.slice (1); // Simplified = ["June", "09", "200 9"];
When it's using RegEx, I find this site extremely useful:
It provides a JavaScript Regex Tester which is very easy! You can plug in the same data and a regex and can run it and see matching data. It helps me to understand regular expressions better, for example, you can see that my regex and other answers are different but complete the same thing.
Comments
Post a Comment