jquery - Split each string from any given paragraph in javascript -
i have textarea. trying split each string paragraph, has proper grammar based punctuation delimiters ,.!? or more if any.
i trying achieve using javascript. trying such strings in using regular expression in answer
but here, in javascript me it's not working. here's code snippet more clarity
$('#split').click(function(){ var textareacontent = $('#textarea').val(); //split string i.e.., textarea content var splittedarray = textareacontent.split("\\w+"); alert("splitted array "+splittedarray); var lengthofsplittedarray = splittedarray.length; alert('lengthoftext '+lengthofsplittedarray); });
since unable split, showing length 1. apt regular expression here.
the regular expression shouldn't differ between java , javascript, .split()
method in java accepts regular expression string. if want use regular expression in javascript, need create one...like so:
.split(/\w+/)
demo: http://jsfiddle.net/s3b5j/
notice /
, /
create regular expression literal. java version needed 2 "\" because enclosed in string.
reference:
Comments
Post a Comment