Regular expression designed to admit only a maximum of two underscore characters, as well as no other special characters, with the condition that the character prior or

Looking for a specific format within a string, such as SOM_P9ERR96M27VP4_PL. The conditions are: must have exactly two underscores, not at the beginning or end of the string, and no other special characters like "&*$," following the underscore. Additionally, a character must follow the underscore and consecutive underscores (__) are not allowed. Using this regular expression

/^(?![_])^[^_]*(_[^_]*){2}[^_](|_[a-zA-Z0-9])$/
fulfills most requirements, except the restriction on consecutive underscores, such as SOM__P9QTR96M27VP4PL.

Answer №1

To enhance the pattern, you may adjust it to identify 2 instances of the character class [a-zA-Z0-9]+ connected by an underscore, and then another instance of the character class [a-zA-Z0-9]+ at the end.

This modification ensures that there are exactly 2 underscores in total, not at the beginning or end, and not consecutively repeated.

^[a-zA-Z0-9]+_[a-zA-Z0-9]+_[a-zA-Z0-9]+$

See the Regex demo here

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

Error in form action when generated through an ajax partial in Ruby

I am facing an issue with a form that is loaded via an ajax partial. The problem arises when the form loads through ajax as it targets the wrong controller/url instead of the intended one. Despite my efforts to set the target controller correctly, it keeps ...

Help Needed: Adding a Simple Element to jQuery Tabs Script

I recently came across a fantastic jQuery tabs script on a website called Tutorialzine. The link to the article can be found here. As I was implementing this script, I realized I needed to customize it by adding specific classes to certain tabs. Specifica ...

Tips for displaying a modal to a user only once

I've developed a Flask application that enables multiple users to register and log in. To achieve this, I have incorporated sessions into my code. When new users land on the initial page, they are greeted with a modal introducing them to the platform. ...

Retrieve active route information from another component

We are utilizing a component (ka-cockpit-panel) that is not linked to any route and manually inserted into another component like so: .. ... <section class="ka-cockpit-panel cockpit-1 pull-left"> <ka-cockpit-panel></ka- ...

Executing several Ajax requests at once can decrease the speed of the process

When I make simultaneous API calls using Ajax, the process seems to be slow as JavaScript waits for all API responses instead of fetching them asynchronously. For instance, /api/test1 usually responds in 5 seconds and /api/test2 also responds in 5 seconds ...

Preserve data across all pages using sessions

On my website, I have a pagination system where each page displays 10 data entries. Whenever a user clicks on the pagination buttons, it triggers a request to the database to fetch the corresponding records. Each data entry also includes a button that can ...

EJS include function not working properly

In most cases, my EJS pages include the code below: <%- include('elements/fbviewpagepixel.ejs') %> Everything runs smoothly except for one particular page where I encountered an error message stating include is not a function. I managed t ...

Top scenario and illustration of utilizing clusters in nodejs

I've been exploring the concept of clusters and I'm still a bit unclear about the most effective use-case scenario for them. Can anyone provide an example to help clarify this for me? ...

What is the mechanism behind the fallthrough behavior when using express.static()?

Hey there, I have a simple express setup like this: const path = require("path"); const express = require("express"); const app = express(); app.use(express.static(path.join(__dirname, "public"))); app.get("/", (r ...

Error! React is unable to find the window object

I recently added the "react-speech" package to my application in order to incorporate text-to-speech functionality. However, upon importing the package, I encountered an error that has been challenging to resolve despite extensive research. Any assistance ...

Implementing an Onclick function in HTML

I have an HTML code and I am looking to add an onclick event for a button named GET DATA. When the button is clicked, I want to send data for userId and categoryId to a PHP file. Can someone help me implement this functionality in my existing code? Here ...

Updating a model within an ng-repeat directive from external sources

Within my controller, there is a repeater where each item has its own unique status: <div ng-controller="..."> <div ng-repeat"...">{{status}}</div> </div> Currently, changing the status within the repeater by using status = &apo ...

Automate the population of input fields

I am working on a React application that utilizes Bootstrap. I have an input field that I want to automatically fill with a name when the user clicks a button. Initially, this input field should be empty, as the variable name = "". When the butto ...

Identify whether a specific Instagram post is a video by utilizing Python with selenium

Good day, After reviewing the content on this post: () I managed to extract specific data using the following code: likes = driver.execute_script('''return document.getElementsByClassName('Nm9Fw')[0].lastElementChild.getElement ...

Including a label for an array within an unnamed array in a JSON string

Is there a way to transform the following data: [{"name": "Donald"}, {"name": "George"}] Into this format instead: {MyArray: [{"name": "Donald"}, {"name": "George"}]} I am currently working on a database server that I built using node.js, express, an ...

Using Typescript to change a JSON array of objects into a string array

I'm currently working with the latest version of Angular 2. My goal is to take a JSON array like this: jsonObject = [ {"name": "Bill Gates"}, {"name": "Max Payne"}, {"name": "Trump"}, {"name": "Obama"} ]; and convert it into a st ...

Is it possible for JavaScript to interface with MySQL databases?

Is it possible to establish a connection between JavaScript and MySQL? If yes, what is the process? ...

What is the method for keeping the first column of the table fixed in place?

Incorporating jquery EasyUI, I have created a table where I want the first column to remain static while the rest of the columns scroll when the screen size is reduced. Code snippet available here. Is there a way to freeze just the Title1 column? I attem ...

Issues with ng-click functionality in MVC partial view

I am currently working on a single page application that utilizes angular.js and MVC. Within the application, there are two partial views being called: Menu Accounts The Menu partial view loads successfully. However, I am encountering an issue with the ...

What is the best way to incorporate an ID from a scala template into an AJAX request?

In my application built on the Play Framework 2.3.8, users can input questions and answers. The view class receives a List[Question] which is iterated through using a for each loop to display them: @for(question <- questionList){ <!-- Questions --& ...