What could be causing this regex to malfunction?

I'm currently working on a regex pattern for validating addresses and I seem to be encountering an issue. Even though my pattern looks correct, the test method does not return true. Can someone help spot what may be wrong with my code snippet below?

let reg=/[0-9]{3}\b[a-z]{1}\b\d{2}[a-z]{2}\b[a-z]{2}\b[a-z}{6}\b[a-z]{10}\b[0-9]{5}/;

let fakeAddress="925 s 10th st tacoma washington 98405";
reg.test(fakeAddress);

Answer №1

When looking for whitespace between letters and digits, remember that there are no boundaries between them. The \b, a word boundary, is a zero-width assertion that does not consume any characters. To match whitespace instead, replace all instances of \b with \s+ (signifying one or more whitespace characters). Also, note that [a-z} is incorrect; it should be [a-z].

To properly match, use this regex pattern:

/\d{3}\s+[a-z]\s+\d{2}[a-z]{2}\s+[a-z]{2}\s+[a-z]{6}\s+[a-z]{10}\s+[0-9]{5}/

For an example, visit the regex demo page

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

What steps should be taken to ensure compatibility between a 4.X Typescript project and an older version like 3.X?

What are the steps to ensure a package developed using TS 4.X is compatible with 3.X? This means leveraging new features for newer versions while fallback to any or unknown for older versions. Can directives be utilized for this specific purpose? Check ou ...

After making the request, $.getJSON initially comes back as undefined but eventually delivers

I found myself in a sticky situation. I was working on coding a Wikipedia search tool for a personal project, but encountered a small glitch. When a user types a word into the search bar, it gets stored in the data parameter of $.getJSON. The response then ...

manage data from multiple users using node.js and socket.io

After extensive searching on this site and across the web, I have yet to find a satisfactory answer to my query. I am in the process of developing a small multiplayer web game using node.js + socket.io for the back-end. To handle new users, I have written ...

Create seamless communication between Angular application and React build

I am currently engaged in a project that involves integrating a React widget into an Angular application. The component I'm working on functions as a chatbot. Here is the App.tsx file (written in TypeScript) which serves as the entry point for the Rea ...

HTML Client Lightswitch: Assign value to modal picker upon screen initialization

After conducting a considerable amount of research on this issue, I have found that none of the examples provided are helpful or applicable. My goal is to have the Details Picker display a specific name when the Add screen loads, instead of requiring the u ...

Troubleshooting a dysfunctional Vue.js component

I am currently facing a challenge in getting components to function properly. Interestingly, without the component, everything seems to be working fine (as per the commented code). Here is my HTML snippet: <strong>Total Price:</strong> <sp ...

Using Javascript to add the current date and time into a mysqli query

Currently, I have a database setup with a datetime data type for landing time. I am trying to achieve this using Javascript. The format in the database appears as: 0000-00-00 00:00:00 I have made an attempt with the following code: $('#landing_tim ...

Efficiently transferring data in segments within an HTML table using jQuery

My HTML code looks like this: <table id="library_info_tbl"> <thead> <th>Call No.</th> <th>Book</th> <th>Accession No.</th> <th>Status</th> </thead> <tbody& ...

Having trouble with axios not transferring data to Express server in React (File upload)?

Hey there! I've encountered an issue with my React client and Express Server. When attempting to send data from the React client to the Express Server, it's not reaching its destination despite trying two different approaches. First Approach: U ...

Steps for sending an API request using the WSO2 Enterprise Service Bus

After carefully following the instructions provided in this tutorial, I attempted to invoke the API through the ESB using port 8280. However, I encountered error code 202 despite not specifying any fault sequence. I diligently followed each step and verif ...

Ways to verify several null values in Angular

In my Angular application, I have 3 ngModel bindings in the UI that are selected by the user using a multi-select dropdown. country = ["India", "US"] state = ["Delhi", "MP","UP"] city = ["gzb","xyz"] A custom filter is used to filter data based on thes ...

The database has unfortunately registered an incorrect value for the "date" input after it was saved

When I select a date from the datepicker input field, it is being incorrectly saved in the database. I am selecting the date using the datepicker and then using AngularJS to send it to Spring MVC AngularJS: $scope.updateProjectDetails = function(detail) ...

angularjs potentially unsafe:data warning appears when taking a screenshot using html2canvas

While using angularjs and html2canvas for capturing a screenshot, I have encountered some issues. The screenshot captures successfully on some screens, but not on others. I am getting the following error: https://i.sstatic.net/FVNym.png I have tried to re ...

Unexpected behavior encountered when using the $http.post method

I've been working with a component that I utilized to submit data to the Rest API. The code snippet for the component is as follows: (function(angular) { 'use strict'; angular.module('ComponentRelease', ['ServiceR ...

unresolved string constant issue with a django template command

I encountered an issue with the code snippet below, which is resulting in an unterminated string literal error: $(function() { $('#addDropdown').click(function() { var $d = $('{{ form |bootstrap }}').fadeIn(). ...

How to Retrieve a Variable from the Parent Component in a Child Component using Angular (1.5) JS

I am currently working on abstracting the concept of a ticket list building into an angular application using 2 components. 1st component --> ("Smart Component") utilizes $http to fetch data and populate an array called populatedList within the parent ...

Maximizing code efficiency with jQuery toggleClass

After creating a code to validate input fields for empty values, I've come to realize that using jQuery toggleClass could potentially enhance or optimize it. However, I'm stuck on how to go about implementing this improvement. Any assistance woul ...

What purpose do the double brackets serve in JavaScript syntax?

I'm seeking clarification on a specific line within the function provided below: , results = [[letters.shift()]] Could you explain what the double bracket signifies in this context? function generateStringPermutations(str) { let letters = str ...

The peculiar behavior of Google Maps markers refreshing inconsistently upon bounds adjustment

I recently completed a project involving a restaurant app using Vue and Google Maps. While everything is functional, I have encountered a persistent bug with the markers. When navigating on the map and the bounds change, some markers seem to disappear. Ev ...

The size of the array within the object does not align

I've run into a roadblock while attempting to implement the tree hierarchy in D3. Initially, I believed that I had correctly structured the JSON data, but upon inspecting the object using Developer's Tool, a discrepancy caught my eye: https://i. ...