Discovering a method to identify a minimum of two pairs of letters that are not adjacent

After using 'aabcc'.match(/(\w)\1+/g) to find repeated pairs of letters, I'm now looking to update my regex to specifically identify non-adjacent pairs. Any suggestions on how to achieve this? For instance:

  • The string 'aabcc' is great because it contains two non-adjacent pairs of letters.
  • However, the string 'aacc' does not meet the criteria for a good string.

Answer №1

Check if a given string consists of consecutive identical letters only, returning false if so:

function verifyString(s) {
  return !/^(?:(\w)\1+)+$/.test(s);
}
console.log(verifyString('aabcc'));
console.log(verifyString('aacc'));

The ^(?:(\w)\1+)+$ pattern matches as follows:

  • ^ - beginning of the string
  • (?:(\w)\1+)+ - one or more instances of:
    • (\w) - a word character captured in Group 1
    • \1+ - one or more occurrences of the value stored in Group 1
  • $ - end of the string.

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

Analyzing the interaction of AngularJS across different pages

I am currently working on an Angular application that consists of a login page and a landing page. My goal is to create a Protractor assertion that can verify the successful login and ensure that the landing page displays correct content. The login proces ...

Enhance or Delete Dynamic linked select boxes in Laravel

Here is a straightforward dynamic form where you can choose a country from the first select box and it will display all the states of that country in each row. Initially, it worked fine for the first row but when I clicked on "Add More" and selected anothe ...

JavaScript redirecting without refreshing the page

Currently, I am faced with a dilemma involving an Ajax function that calls a remote site, saves data to a database, and then needs to refresh the current page to display the new information. The complication arises from the fact that tabs are being utilize ...

I will see the "undefined" entity displayed in the bar chart created using react-chartjs

Using the react-chartjs-2 library, I created a bar chart with the following data: const chartData = { labels: ['Dealer1', 'Dealer2', 'Dealer3', 'Dealer4', 'Dealer5', 'Deal ...

Toggle the visibility of HTML elements by utilizing a JavaScript checkbox event

I have put together these JavaScript functions to hide the delivery address fields on my shopping cart address form if the goods are being sent to the billing address. The functions control the visibility of the HTML wrapped by... function getItem(id) { ...

Form an item using an array

Is there a way to efficiently convert this array into a map? Here is how the array looks: var array = [{ "id" : 123 }, { "id" : 456 }, { "id" : 789 }]; The desired output should be: var result = { "123": { id: 123 } , "456": { id: 456 } , ...

Ways to guarantee that the factory promise is fulfilled prior to the execution of the

So far, I have always found valuable help by studying existing answers on stackoverflow, but now I've hit a roadblock. I'm currently working on an app that utilizes a directive to generate calendar month boxes. <app2directive class="column_5 ...

Retrieving Data using Map in ReactJS

I'm in the process of creating a web app and I have an array of data with URLs in each element. I'm struggling to figure out how to fetch data from these mapped URLs. useEffect(() => { axios .get(`someurl`) .then((response) =& ...

Create a duplicate of the sapUI5 JSON model and end the data binding process

I've encountered a similar issue, but the solution doesn't seem to work for me. I have a JSON model named "data" that represents a SAPUi5 form with comboboxes. My goal is to capture the initial state of the model when the application is first ope ...

Issues arise with User obj's utilization of the Instagram API

After setting up my Instagram developer account, I was able to obtain the client_secret and client_id. Authentication went smoothly for my own user (myusername), and I received an access_token. However, when attempting to utilize this endpoint TOKEN] Fo ...

The issue with the `.load` function in jQuery not functioning properly

I'm currently tackling an issue with a project where I am encountering difficulties with the .load function not working in Google Chrome. Below is the JavaScript code: function link1() { $('#loadarea').html('loading.....' ...

Having difficulties with the edit function in JavaScript To Do Application

After creating an edit button to modify a task, it functions properly for the initial task I create. However, when attempting to edit subsequent tasks, the edit function defaults back to modifying the input of the first task instead. With each new ta ...

How to modify the color of the placeholder text in a select dropdown using Material-ui

I have a material-ui select component that displays a dropdown menu of options for the user to choose from. The placeholder text, which currently reads "select option," appears in light grey to prompt the user to make a selection. However, I am concerned t ...

Preventing Users from Pressing the Return Button on the Browser

After reviewing this code snippet on W3 schools : window.addEventListener("beforeunload", function(event) { event.returnValue = "Write a thoughtful message here.."; }); You have the option to implement this on one of your HTML elements, but how can you ...

Issue in JavaScript on IE9: SCRIPT5022 error: DOM Exception - INVALID_CHARACTER_ERR (5)

I am encountering an error with the following line of code: var input2 = document.createElement('<input name=\'password\' type=\'password\' id=\'password\' onblur=\'checkCopy(th ...

The current date is indicating that the date string provided is invalid for interpretation by dayjs()

Have you tried using DayJs? If you're working on the browser, specifically with Firefox + Vue + typescript, here's my date string: 2021-02-05 12:00 AM However, when I include the AM/PM in the code like this: const dateObj: any = dayjs('2 ...

Even though setState is supposed to update the state and trigger a render, it's not showing up in the view for some

My React app consists of a simple word/definition feature. There is an edit box that appears for users to change the definition when they click on "edit". Even though I call getGlossary() to update the new definition in the state, I can see the changes in ...

Is it possible to set up multiple registries within a single package.json configuration?

Is it possible to define two different registries within the publishConfig section of the package.json file? The scenario is that we want to publish the artifact to two different locations depending on its purpose. For SNAPSHOT versions, we would like to ...

Enhancing Luxon DateTime with extension type support

Referencing the issue at https://github.com/moment/luxon/issues/260, I am looking to extend the DateTime object as shown below: import { DateTime } from 'luxon'; function fromUnix(tsp?: number): DateTime { return DateTime.fromMillis(tsp * 1000 ...

Tips on transitioning between two tables

Recently, I created an HTML page entirely in French. Now, I am attempting to incorporate a language translation feature on the website that allows users to switch between French and English (represented by two flag icons). My concept involves using a tabl ...