Advertisement
Guest User

Untitled

a guest
Oct 28th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. (?<= # Positive look-behind
  2. b # Word boundary
  3. | # Or
  4. _ # Underscore
  5. ) # End group
  6. d # Digit
  7. (?= # Positive look-ahead
  8. b|_) # Word boundary or underscore
  9.  
  10. const manualBoundaries = /d/g
  11. const matches = [];
  12. while ((match = manualBoundaries.exec(str)) !== null) {
  13. const m = match[0]
  14. const i = match.index
  15. if ((i == 0 || str[i - 1].match(/(W|_)/)) &&
  16. (i + m.length == str.length || str[i + m.length].match(/(W|_)/)))
  17. matches.push(m)
  18. }
  19.  
  20. const matches = [];
  21. str.replace(manualBoundaries, (m, i) => {
  22. if ((i == 0 || str[i - 1].match(/(W|_)/)) &&
  23. (i + m.length == str.length || str[i + m.length].match(/(W|_)/)))
  24. matches.push(m);
  25. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement