When symbols are detected within quotes, the regex value will give a false output

Having trouble with my regex to extract special characters not enclosed within double quotes - the test function always returns false.

As a beginner in regex, any advice or guidance would be greatly appreciated.

Check out my Regex here

test.html

<input 
    class="bg-white appearance-none border border-black rounded w-full py-2 px-4 text-black leading-tight focus:outline-none focus:bg-white focus:ring-0 focus:shadow-none ring-offset-0 focus:border-primary dark:bg-gray-800 dark:text-gray-300 m-3"
    id="inline-full-name" type="text" [maxlength]="maxChars" [(ngModel)]="newproxyAddr" (ngModelChange)="validation($event)">

test.ts

public validation(addr: any) {
 
  const checkEnclosedPattern = /[][@()\[\]{};,:.<>](?=(?:(?:[^"]*"){2})*[^"]*$)/
    
  console.log(checkEnclosedPattern.test(addr.toString()))
}

Answer №1

When using ECMAScript flavor in Regex101, your regex may not function correctly.

The issue arises because the opening [] is interpreted as an empty character class that matches null.

To resolve this, you can simply remove the initial [] since you have already accounted for \[ and \].

[@()\[\]{};,:.<>](?=(?:(?:[^"]*"){2})*[^"]*$)

Check out a demo on Regex 101

See a demo on StackBlitz

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 return type should be used when returning `_.orderBy` from a TypeScript function?

The current packages I have installed are lodash and @types/lodash. In my code, I am using: import _ from 'lodash'; function doSomething(): string[] { const letters = ['c', 'a', 'b']; return _.orderBy(letters ...

Invalidating Angular Guards

My goal is to have my auth guard determine access privileges using an observable that periodically toggles a boolean value. My initial approach was as follows: auth$ = interval(5000).pipe(map((n) => n % 2 === 0)); canActivate( next: ActivatedRoute ...

Integration of NextAuth with Typescript in nextjs is a powerful tool for authentication

I am diving into NextAuth for the first time, especially with all the new changes in Nextjs 13. Setting up nextauth on my project seems to be a daunting task. I have gone through the documentation here I am struggling to configure it for nextjs 13. How do ...

(TS) When defining a 'const' enum, the member initializer must be a constant expression

I'm encountering an issue while building my application in Visual Studio 2017. The project is using ASP.NET CORE 2 and Angular 6. Once I run the application, errors are popping up in the file output_ast.d.ts within the node_modules directory: (TS) ...

Connecting the SelectedItem of a listbox in ngPrime to an Observable Collection in Angular2

I am facing an issue while trying to use the ngPrime listbox in Angular2. I have a scenario where I am fetching an array of objects from Firebase as an observable and attempting to display it correctly in the listbox. <div *ngIf="addContactDialogVisibl ...

Is there a way to adjust the starting and ending points of a bezier curve in D3 by utilizing the link generator?

I'm currently working on developing a horizontal hierarchical tree Power BI custom visual using TypeScript and D3. I am utilizing d3's treeLayout for this purpose, and my task is to create a link generator that can plot bezier, step, and diagonal ...

Generate the Ionic build and save it to the /dist directory instead of the /www

Every time I execute the command ionic build, it generates a fresh /dist directory containing all the same files that are typically found in the /www directory. Despite my attempts to make updates to the /www folder, only the /dist folder gets updated. Wha ...

When a function containing multiple statements is utilized to generate a template string for an angular component, an error may occur indicating that the value cannot be statically determined

I'm experimenting with creating my component template dynamically using the following approach. import { Component } from "@angular/core"; function getTemplate() { let temp = ""; for (let index = 0; index < 5; index++) { ...

Utilizing a TypeScript definition file (.d.ts) for typings in JavaScript code does not provide alerts for errors regarding primitive types

In my JavaScript component, I have a simple exporting statement: ./component/index.js : export const t = 'string value'; This component also has a TypeScript definition file: ./component/index.d.ts : export const t: number; A very basic Typ ...

Exposing the method to the outside world by making it public in

I have a situation where I have a base class with a protected method called foo, and a child class that needs to make this method publicly accessible. Since this method will be called frequently, I am looking for a more efficient solution to avoid unnecess ...

Encountering an issue when utilizing createStore in conjunction with TypeScript and the thunk

I am currently learning TypeScript and attempting to migrate a React application to use TypeScript. I encountered an issue when utilizing the createStore function from 'redux' in my index.tsx file, resulting in the following error message. Type ...

Leverage Angular to implement Bootstrap 5 tooltip on elements created dynamically

Our Angular-14 application uses Bootstrap-5 and I am currently attempting to add a tooltip to an element that is dynamically created after the page loads. The new element is based on an existing element, shown below: <span [ngbTooltip]="tipSEConte ...

The 'setComputed' property is not mandatory in the type definition, however, it is a necessary component in the 'EntityExample' type

I'm encountering an issue while trying to create a factory for updating an entity. The error I'm facing is related to the usage of afterload: Entity: import { Entity, PrimaryGeneratedColumn, Column, OneToMany, BaseEntity, AfterLoad, ...

Turn off the warning message that says 'Type of property circularly references itself in mapped type' or find a solution to bypass it

Is there a way to disable this specific error throughout my entire project, or is there a workaround available? The error message states: "Type of property 'UID' circularly references itself in mapped type 'Partial'.ts(2615)" https:/ ...

Selecting the checkbox to populate the input field

In my application, there is an input field that can be filled either by searching for an item or by clicking on a checkbox. When the user clicks on the checkbox, the input should be automatically filled with the default value valueText. How can I detect ...

Ways to Obtain Device Identification in Ionic 2 Utilizing TypeScript

Can anyone help me with getting the device ID in ionic2 using typescript? I have already installed the cordova-plugin-device Here is my code snippet: platform.ready().then(() => { console.log(device.cordova); } Unfortunately, this code doesn&apos ...

The URL for my JSON file cannot be located on my Angular server

Hey there! I'm currently working on setting up a server that will be pulling product data from a JSON file using HTTP. However, I've encountered an issue during the application build process where this error message pops up: Failed to load resou ...

Leveraging components from external modules within sub-modules

So, I've created a module to export a component for use in different modules. However, I'm facing an issue with how to properly utilize this component within child modules of another parent module. While I have imported the first module into the ...

Retrieve data from Outlook Calendar API by utilizing OAuth2 protocol

I have been working with calendar APIs in .NET Core and Angular. After successfully integrating the Google Calendar API, I am now looking to implement the Outlook Calendar API as well. To start off, I need to create a function in Angular that will allow me ...

Jest encountering errors when compiling a generic function

I'm able to successfully run my Node app, but running tests on a class with Generics is causing an error. The test code looks like this: import { Request, Response } from 'express'; import { JsonWebTokenError } from 'jsonwebtoken' ...