Patterns that occur in the negative look behind JavaScript in regular expressions

Despite its seemingly trivial nature, I am struggling to identify the mistake in my approach. I am attempting to recognize sentence endings by using a regular expression to locate periods. However, I only want to detect periods that follow a word with more than two letters to avoid false positives like "St. Nicholas."

The current expression I am using is:

/\w{3,}\./g

Unfortunately, this pattern seems to be capturing the entire word instead of just the period. What could be the issue here?

UPDATE:
I am looking for

"St. Kitts is really cool. Like seriously, sweet."

To match the periods after both "cool" and "sweet," but not after "St."

UPDATE 2:
Since I am working in Javascript, a standard lookbehind like (?<=text) will not work.

Answer №1

To utilize groups effectively, follow these steps:

let pattern = \d{2,}(\.);
let result = pattern.exec(input);
alert(result[1]);  // Make sure to capture the period

In case there are multiple periods present:

result = pattern.exec(myInput);
while (result != null) {
    // matched period: result[1]        
    result = pattern.exec(myInput);
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The ion-datetime in Ionic 4 ensures that the floating label always remains visible, even when the input

When an ion-datetime field in Ionic 4 has no value, the label always floats as shown below. Here is my code snippet: <form [formGroup]="statusHandlerForm"> <ion-item class="input-container " align-items-center no-padding> <ion-la ...

Pondering in AngularJS - what is the best way to alter the DOM during an AJAX call?

I'm completely new to AngularJS and trying to transition from a jQuery background. After reading through "Thinking in AngularJS if I have a jQuery background?" on Stack Overflow, I understand the concept but am struggling to implement it without depen ...

The MIME type for .rar and .tar files is not specified

Why is it that Javascript (Windows 8.1, Firefox) doesn't seem to recognize mime types for .tar files or .rar files, among others? Is there a way to fix this issue without resorting to unconventional methods? I really need to be able to get the mime ty ...

Exploring ES6: Harnessing the Power of Classes

I am currently learning the ES6 syntax for classes. My background is in C#, so I apologize if my terminology is not accurate or if something seems off. For practice, I am working on building a web app using Node and Express. I have defined some routes as ...

Creating an element that remains fixed once it reaches a distance of 50px from the top of the screen

Hey there! I'm working with an html div element that currently scrolls along with the page, but I was wondering how I can make it become fixed once it reaches a distance of 50px from the top of the screen. Any ideas on how to achieve this? Just to pro ...

Challenges with retrieving all text records in a profile using ethers.js

Currently, I am facing difficulties in retrieving all ENS text records from a profile due to issues with the logic or potential approaches... With ethers.js v6, my current strategy involves fetching all the log data and then sifting through it. However, t ...

Is assigning an ID to multiple objects a poor decision?

While working on my Django project, the template quickly became cluttered with elements all having unique IDs. I could reduce the number of IDs by assigning them to their parent elements, but this would require longer jQuery code. So now I'm faced wit ...

Most effective method for generating numerous branching arrays in JavaScript

When creating shorthand objects, I find that there are too many indents with other arrays and objects inside. I am building a question form that branches out to new sets of questions based on the previous one answered. Do you have any suggestions on how ...

No Ajax request is being made for the WebMethod

I am attempting to utilize a WebMethod by using a function that includes an Ajax Call request. However, I keep receiving an Internal Server error 500. Below is the function with the Ajax call: function ajaxCall(URL) { var serverData = ""; $.ajax({ u ...

Tips for designing JavaScript functionality to avoid handling transparent image regions when hovering and clicking

I have searched through various sources on this subject, but none seem to directly address my specific requirements. My main objective is to replicate the Nike ID Flash-based customization using html5, css3, and javascript. My initial thought was to cut a ...

trouble encountered when attempting to integrate typeahead functionality in AngularJS using jQuery

Greetings! I am brand new to using AngularJS and currently exploring the implementation of typeahead functionality. I decided to utilize an existing library by including the following script: <script src="lib/xyz/typeahead.bundle.js"></script> ...

Change Observable<String[]> into Observable<DataType[]>

I'm currently working with an API that provides me with an Array<string> of IDs when given an original ID (one to many relationship). My goal is to make individual HTTP requests for each of these IDs in order to retrieve the associated data from ...

Cause: Trying to serialize an `object` that is not JSON serializable (such as a "[object Date]"). Ensure that only JSON serializable data types are returned

Currently, I am utilizing Prisma along with Next.js. My issue arises when attempting to retrieve content from Prisma within the getStaticProps function; while it successfully fetches the data, I encounter difficulties passing it on to the main component. e ...

Using npm as a build tool to merge files together

Upon discovering the flexibility of using npm as a task runner instead of gulp or grunt, I have successfully implemented various tasks such as linting, stylus processing, jade compilation, uglifying, and even watching files. However, I am facing difficulti ...

Creating a dynamic Three.js scene based on a variable

Having limited knowledge in html/javascript, I decided to start with three.js. My scene relies on a parameter that users can manipulate. Below is a simple example of the scene setup. It showcases a parametric surface that adjusts based on a user-controlle ...

Unable to obtain an HTML extension while utilizing handlebars

Sorry if this is a silly question, but I'm having trouble figuring it out. I'm using express-handlebars and trying to name my file newpage.handlebars. However, it keeps saving as a text file instead of an HTML extension, even though I want the na ...

Capture an image of a webpage and print it out

I am currently in the process of designing a web page and one of the key features I need is a button that allows users to print a selected area. After conducting several searches, I came across html2canvas as a potential solution. I proceeded to install it ...

Regular expression to ignore the expression if it is found within a table

Looking to capture an expression, but only if it's not within a table using Ruby. hello. <p> <b> 1 capture </b> </p> <table class="tb1"> <tr> <td> <p> <b> 1 don't capt ...

I need assistance setting up a Facebook page feed using Angular.js. I want to display the posts in a list of cards and include a fullscreen image gallery. Is

Hey there! I'm in the process of developing an app that pulls Facebook page posts and showcases them with custom CSS. The app is functioning smoothly with two controllers, DashCtrl and MainCtrl, each working fine on its own. However, when trying to tr ...

Is there a way to trigger a re-render in React when another user is adding new data to the database?

How can I develop a straightforward forum platform that allows users to add, delete, and modify posts stored in a database? Currently, I have a basic authentication application set up with a client-side React app and a server using Express. Is it feasibl ...