Skip to content

Use word boundaries for word matching? #17

Description

@ryanpcmcquen

Is there a reason the analyzeNote function doesn't use word boundaries?

  analyzeNote() {
    var s = this.state.note.content.text;
    s = s.replace(/(^\s*)|(\s*$)/gi,"");//exclude  start and end white-space
    s = s.replace(/[ ]{2,}/gi," ");//2 or more space to 1
    s = s.replace(/\n /,"\n"); // exclude newline with a start spacing
    let wordCount = s.split(' ').length;
    this.setState({wordCount: wordCount});
  }

Would become:

  analyzeNote() {
	// Count all word boundaries in the note text and divide by 2
	// to get the word count:
    let wordCount = this.state.note.content.text.match(/\b/gm).length / 2;
    this.setState({wordCount: wordCount});
  }

If this is OK, I'll set up PRs to change it here and in the documentation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions