fork download
  1. let pattern = /\b(?:(?:Mr|Miss|dr|lord)? )?((?:[A-Z]\w*(?:[ -][A-Z]\w*[.]?)*|[a-z]+(?: [a-z]+)))\b/;
  2. let strings = [
  3. "Mr Bob Smith",
  4. "Miss Jessica Blue",
  5. "tim white",
  6. "dr Lisa S pink",
  7. "lord Lee Kensington-Smithe",
  8. "William R. Burroughs III"
  9. ];
  10.  
  11. strings.forEach(s => {
  12. let m = s.match(pattern);
  13.  
  14. if (m) {
  15. print(m[1].split(" ").map(s => s.charAt(0).toUpperCase()).join(""));
  16. }
  17. });
Success #stdin #stdout 0.04s 17440KB
stdin
Standard input is empty
stdout
BS
JB
TW
LS
LK
WRBI