javascript - Regexp assistance -
i'm not experience regexp , have been struggling match of use cases attempts have made, wondering if suggest match may cover following scenarios. need extract volume i.e. 250ml string.
- vanilla blossom 250ml body wash
- vanilla blossom 250 ml body wash
- vanilla blossom body wash 250ml
- 250ml vanilla blossom body wash
- vanilla blossom 20g soap
- vanilla blossom 20 g soap
thanks
let arr = ['vanilla blossom 250ml body wash', 'vanilla blossom 250 ml body wash', 'vanilla blossom body wash 250ml', '250ml vanilla blossom body wash', 'vanilla blossom 20g soap', 'vanilla blossom 20 g soap', 'vanilla blossom 20 dag soap', 'vanilla blossom 20dag soap' ]; let reg = /(?:\d+[ ]{0,1})(?:ml|g)/i; console.log(arr.map(str => str.match(reg)));
Comments
Post a Comment