How does .match() differ from simple .replace(); How to use match option list with phrases
See original GitHub issueTrying 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:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
ohhh, sorry i misunderstood. yeah, the multiple-word inside of
( )
is pretty awkward right now. you may have better luck with.lookup()
:https://runkit.com/spencermountain/5e612505ecbc3d00138ed3ad cheers
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