Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Way to implement better regex in Node.js

I'm using Node.js for a project, and I'm finding Javascript's regex syntax very limiting. Specifically the lack of lookbehind is killing me. I'm trying to use regex to parse strings into sentences, but I want to check for common abbreviations such as Mr. and Mrs. so that I don't break the sentences up. Is their a Node.js library that adds regex features, and if not what would a good course of action be?

like image 966
user2084028 Avatar asked Oct 21 '22 07:10

user2084028


1 Answers

It's the difficulty with javascript regexes,

A way to avoid your specific problem:

/((?:Mrs?\.)|[^\.]+)+/  # match all that is not a dot or Mr. or Mrs.

For more tricks, you can take a look at this site: http://blog.stevenlevithan.com/archives/javascript-regex-lookbehind

like image 64
Casimir et Hippolyte Avatar answered Oct 24 '22 10:10

Casimir et Hippolyte