The occurrence of 4 or more consecutive identical letters

Does anyone know how to modify my current RegEx expression to disallow 4 or more consecutive letters of the same kind? Here is what I have so far:

(^[A-Za-z]{1})([A-Za-z\-\'\s]{0,})([A-Za-z]{1}$)

It fulfills almost all of my criteria, except for one:

  • Any alphabetic character
  • Single spaces, but not as the first or last character
  • Hyphens, but not as the first or last character
  • Single quotes, but not as the first or last character
  • No more than 3 consecutive characters of the same kind, regardless of case
  • Must be at least 2 characters long, when present

Here are some examples:

James        - valid  
Sarah Jayne  - valid  
Michellle    - valid  
O'Brian      - valid  
Holly-Rose   - valid  
Eeeeric      - invalid  
Jo--anne     - invalid

Answer №1

After carefully analyzing your description, edits, and comment, I have come up with a suitable regex solution in Javascript:

/^(?=.{2})(?!.*([a-z])\1{3})[a-z]+(?:[' -][a-z]+)*$/gmi

Check out the RegEx Demo here

Key points of the regex:

  • (?=.{2}) - Positive lookahead to ensure the input has at least 2 characters
  • (?!.*([a-z])\1{3}) Negative lookahead to prevent 4 repetitions of alphabets

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

When passing down data to a child component, the value is not accessible

I'm facing an issue where I am trying to pass down the isOpen prop to the Snackbar component. However, when I try to console.log this.props in either the componentDidMount or componentDidUpdate methods, all I see is this.props.message. I would really ...

Is there a way to include an item into a three.js environment during a mouse click event?

Is it possible to dynamically add a 3D object to a three.js scene after it has been initialized and the user triggers a click event? How can this be achieved within the existing code structure provided? You can find a prepared scene setup in this working ...

Difficulty encountered when validating URLs with ASP.Net Regular Expression Validator

I am struggling to make use of the ASP.Net Regular Expression Validator in order to validate a URL field. The specific URL I am trying to validate is www.tachibana.co.jp/tokyosys.htm. The validation expression that I have used is ValidationExpression="http ...

Can two different versions of a library be utilized simultaneously in NPM?

Currently, our Vue.js app is built with Vuetify v1.5 and we are considering transitioning to Vuetify 2.0. However, the process would involve numerous breaking changes which we currently do not have the resources to address for all components. Is there a wa ...

We encountered an issue: Headers cannot be set after they have been sent while attempting to read files

I encountered an error when attempting to read a file and send the response back to the browser. [ 'Error: Can\'t set headers after they are sent.', ' at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:344:11)&apo ...

Resizing a column to match the dimensions of a grid of pictures

Imagine you have a website structured like this. #left_column { width: 200px; } <div id="left_column"> /* some content */ </div> <div id="right_column"> /* A series of photos each with a width of 100px and floated */ </div> In t ...

sending data from angular controller to a node server

Having trouble with my Angular controller that posts to the node server. The function triggering the post is giving me a 404 (Not Found) error when running it. I've tried rewriting the post multiple times but can't seem to locate the issue. If ...

AngularJS - Triggering functions on image load event

I have been on a quest to find the best way to handle the onload event for images in Angular using jqLite. I came across this question, but I am looking for a solution that involves directives. Therefore, the approach below is not satisfactory to me: .c ...

Emulating a Javascript API request

I'm looking to practice simulating API calls for a VueJS application. Currently, I am fetching data from a hardcoded JSON file that I've created. Within my App.vue: <template> <p>{{ teams.yankees.city }}</p> // Output will b ...

What causes the unexpected behavior of JQuery's .animate() function?

I am currently working on a project that involves creating a div element for the purpose of dragging and dropping files. My goal is to have the height of the div increase when a file is dragged into it, and decrease when the file is dragged out. To achiev ...

attempting to retrieve a specific nested value using square brackets

I am attempting to track the position of an object associated with a particular row. Ultimately, I require a comprehensive object that includes both the row and the position of a "com" within that row. Below is my code snippet: (g represents a global objec ...

Ajax polling ceases the polling process when an internet connection is lost

My current setup involves a continuous ajax polling cycle where messages are pulled, processed, a wait period occurs, and then the process is repeated. Everything runs smoothly until a user disconnects from the internet, whether it be due to a simple actio ...

`Finding and including the additional object in JavaScript`

Seeking guidance on how to manipulate a specific object in Javascript, I have successfully retrieved the object based on a filter, but I am unsure how to append `'in'='bank' and 'out'='bank'` of non-filtered ids to ...

Angular dynamically selects a dropdown option when the page is loaded

Check out this dropdown example: <div class="col-md-6"> <div class="form-group> <label class="control-label">Role</label> < ...

Toggle the visibility of the identical div

I am facing a challenge with dynamically hiding and showing various div elements on my website. I have managed to achieve this using show/hide, but the issue arises when I need to show/hide some of the same fields repeatedly. The script works fine on the f ...

instructions on modifying a singular row within a v-data-table (excluding design changes, focusing on the data itself)

For this specific scenario involving v-data-table, I encountered a challenge in finding an answer. While I am aware that templates and slots can be utilized to modify columns, my query pertains to reflecting values in only one row. Essentially, I aim to ad ...

The quickest regular expression match possible if it is already a subsection of another match

Is there a simple way to find the shortest match in a long text where strings are repeated? I'm having trouble because matches within already matched text aren't being found. Here's an example of the issue: Using code: "ababc".match(/a.+c ...

Unable to refresh data dynamically in pagination using DataTables

Currently, I am implementing a Datatable plugin to enable pagination on my HTML table. Within the table, there is a checkbox for selecting rows and each row possesses a unique ID. However, I am facing an issue when attempting to update cells of a specific ...

Problem encountered when trying to use the sharp package in NuxtJS

I attempted to implement this code in my Nuxt project, but it encountered an issue during compilation. Within my plugin/sharp.js file: import vue from "vue" import sharp from "sharp" vue.use(sharp) And in my nuxt.config.js file: plugi ...

Socket.io integration with JWT authentication

Having some trouble establishing a connection with JWT. It's not returning anything and I'm not very familiar with JWT so not sure where I might be going wrong. Unable to do anything on localhost:4000 due to the lack of connection. Any suggestio ...