question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How does .match() differ from simple .replace(); How to use match option list with phrases

See original GitHub issue

Trying to parse transcription results for instances when the phrase representing the punctuation and replace it with the correct formatting.

I am wondering how .match() differs from a simple search and replace

This is an example at an attempt to use match.

  javascript
  _punctType(results) {
    switch (results.match('[<punctuation>(period|comma|exclamation mark|question mark)]', 'punctuation').text()) {
    case 'period':
      return periodRegex;
    case 'comma':
      return commaRegex;
    case 'exclamation mark':
      return exclamationRegex;
    case 'question mark':
      return questionRegex;
    default:
      break;
    }
  }

In this example use .match() I am not able to get multi-word phrases to be correctly recognized.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
spencermountaincommented, Mar 5, 2020

ohhh, sorry i misunderstood. yeah, the multiple-word inside of ( ) is pretty awkward right now. you may have better luck with .lookup():

let doc=nlp('i used a question mark and nothing else, period.')
doc.lookup(['comma','question mark','period']).out('array')

https://runkit.com/spencermountain/5e612505ecbc3d00138ed3ad cheers

0reactions
spencermountaincommented, Mar 5, 2020

no problem. lookup checks-against the parsed and normalized form of the terms, so it will guard against punctuation, contractions and other shenanigans in the text. it can also be much faster, when working with large # of lookups or texts.

but yeah, if you write some safe regular expressions, you can use a simple javascript replace too

Read more comments on GitHub >

github_iconTop Results From Across the Web

Substitutions in Regular Expressions | Microsoft Learn
Substitutions are language elements that are recognized only within replacement patterns. They use a regular expression pattern to define all or ...
Read more >
JavaScript Regex Match Example – How to Use JS Replace ...
Similar to the .match() method, .replace() will only replace the first matched pattern it finds unless you use regex with the g flag:...
Read more >
Excel MATCH function with formula examples - Ablebits
The MATCH function returns the relative position of the lookup value in the array, not the value itself. MATCH is case-insensitive, meaning it ......
Read more >
INDEX MATCH Explained (An Alternative to VLOOKUP)
In this video I explain how to use the INDEX MATCH formula as an alternative to VLOOKUP in Excel. Download the Excel file: ......
Read more >
Documentation: 15: 9.7. Pattern Matching - PostgreSQL
The SIMILAR TO operator returns true or false depending on whether its pattern matches the given string. It is similar to LIKE ,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found