Skip to content

Tag: regex

Regex to select words with spaces for subsititution

I have string in JS which where I need to add ‘ to the values. Example: task: task one, client: Mr jhon will be converted to task:’task one’, client: ‘Mr Jhon’ Think of these string as user entered search query. This is then sent to the backed for the searching. The values need t…

Dynamically replace data based on matched RegEx JavaScript

I have a dynamic template string, similar to the following: I also have an object like so: How do I replace each template variable with the value presented in an object where the key is the text in the braces. For example: I have tried the following: The code above replaces all instances of text in curly brac…

Angular FormBuilder US Phone Number Regex (xxx) xxx-xxxx

I am trying to write an Angular Regex validator, which matches this and only this pattern for phone, spaces exact How can this be done? Working on this Code: Trying to add the space, after the first parenthesis, not sure if correct Answer You need to Add a literal space (or s to allow any whitespace) exactly …

JS How to test if a string is only an abbreviation?

Any JS Regex expert that could help me return true if the word is only an abbreviation or else false? Tried this regex. But it also returns true for strings like. A.. A.B B.BA.. Greg D. Bot I’m trying to formulate a regex that could only return true for the following: A.B. A.B.C. A.B.C.D. And so on.. An…

Regex for Extracting the Country Name

What regular expression would extract the country name when used with any of the lines below? I’ve got a dropdown with all of these as choices and I’m trying to extract the country only, but I’m failing miserably since JavaScript doesn’t seem to support lookbehinds and I have no idea h…