For a search string like ""foo and bar" or foo", i want to separate string in : 1)"foo and bar" 2)or 3)foo. That means I want to consider the quoted words in a single string. In server side i'm using (Java):
Matcher m = Pattern.compile("([^\"]\\S*|\".+?\")\\s*").matcher(searchText);
while (m.find()) {
String searchTermStr = m.group(1);
list.add(buildSearchTerm(searchTermStr));
}
How can a get similiar output in javascript? I'm trying to split the searchText using this regEx and it's not giving the desired result.
var pattern = new RegExp("([^\"]\\S*|\".+?\")\\s*","gi");
var searchTerms = $scope.searchText.split(pattern);