Reputation: 15303
i am getting a info from back-end. i need to convert that in to multiple word, and to require to store in array. using regexp
how to get that?
here is the word:
Enter Room/Area^_^Area 100#_#Enter Grid^_^Grid2#_#Enter Level / Building^_^Building1#_#Enter Drawing^_^Drawing1#_#Enter Spec section^_^Spec2#_#Enter BOQ^_^BOQ1#_#
the result should be :
["Area 100", "Grid2","Building1", "Drawing1", "Spec2", "BOQ1" ]
So simply i would like to pick the words which end with number. upto the special char ^
.
Upvotes: 1
Views: 68
Reputation: 67968
\b[a-zA-Z0-9 ]+\d+\b
Try this.See demo.
https://regex101.com/r/wZ0iA3/6
var re = /\b[a-zA-Z0-9 ]+\d+\b/gi;
var str = 'Enter Room/Area^_^Area 100#_#Enter Grid^_^Grid2#_#Enter Level / Building^_^Building1#_#Enter Drawing^_^Drawing1#_#Enter Spec section^_^Spec2#_#Enter BOQ^_^BOQ1#_#';
var m;
while ((m = re.exec(str)) != null) {
if (m.index === re.lastIndex) {
re.lastIndex++;
}
// View your result using the m-variable.
// eg m[0] etc.
}
Upvotes: 3