Regular Expressions

A regular expression ("regex") is a sequence of characters that define a search pattern, mainly for use in pattern matching with strings, or string matching, i.e. "find and replace"-like operations. Regular expression processors are found in several search engines, search and replace dialogs of several word processors and text editors, and in the command lines of text processing utilities, such as sed and AWK. Many programming languages provide regular expression capabilities, some built-in, for example Perl, JavaScript, Ruby, AWK, and Tcl, and others via a standard library, for example .NET languages, Java, Python and C++ (since C++11). Most other languages offer regular expressions via a library.

Share tech news, updates, or what's on your mind.

Sign up to Post

Need help with a regular expression that can extract data between ()

Data                         Extract
--------------------
1.2 (3.4L)                    ----> 3.4L
100 (3.4G/Max)        ----->3.4G/MAX
Z (ABC) V                   ------> ABC
ZZZZZ                        ------> Nothing
(X ...MMM                ------->Nothing because not closing bracket
0
Build an E-Commerce Site with Angular 5
LVL 13
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

Hi

I have inhertited a Reg Ex patter to validate mobile phone numbers.

/^(\+44\s?7\d{3}|\(?07\d{3}\)?)\s?\d{3}\s?\d{3}$/g;

I need to change it to validate an 8 digit number, starting with 2.

Can anyone help please.
0
Hi Expert. I could not write the regex command of the following values.
How do I write this regex command?
how to write a regex command that covers the following lines:
12345
1a4a5
12a45
12abc
12abc
12ab5
12aa5
12AB5

Open in new window

thanks
0
I need a regular expression that will extract numbers and "/", ".".

Data Example:            Results:
----------------------           -----------
3.66                               3.66
1-1/34                           1-3/4
N/A                                [null]
Test 3.55                       3.55
5                                     5
0
I need a regular expression to test for mm/dd/yyyy dates at the beginning of lines in a form field, as in the example below:
·07/29/2019 event 3
·07/08/2019-event 2
·05/29/2019: event

Users can enter as many dates and details as they want, but I need to verify the date format.

Users may also enter only one date, as below.

07/29/2019 event

Here's what I have (that doesn't work):

var dateString = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/

But I don't know how to test (or ignore) the bullet character. I've tried .  I've tried \·  

But none of my efforts find the lines below valid (though I want them to be accepted):

·07/29/2019 event 3
·07/08/2019-event 2
·05/29/2019: event

Here's the context in my javascript:  else if(!dateString.test(theForm.EI16.value)) {alert("Please use mm/dd/yyyy format for all dates.");theForm.EI16.focus();return false;}

Who can help?
0
I have a file with more rows.
I want to delete some lines from within this file.
I am using the vi editor.
I wrote a simple sentence.
but it only deletes a single line.
I have to run this code every time.This is a waste of time.
How do I delete the rows I want to delete in a lump ?

MEDULA_ESEVKTAMAM_TANI_PK,--rows I want to delete
  CREATE UNIQUE INDEX "HASTANE"."MEDULA_ESEVKTAMAM_TANI_PK" ON "HASTANE"."MEDULA_ESEVKTAMAM_TANI" ("SIRA_NO", DOSYA_NO, PROTOKOL_NO, "TEDAVI_ICD")
  PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
  TABLESPACE USERS,

MEDULA_ESEVKBILDIR_TANI_PK,--rows I want to delete
  CREATE UNIQUE INDEX "HASTANE"."MEDULA_ESEVKBILDIR_TANI_PK" ON "HASTANE"."MEDULA_ESEVKBILDIR_TANI" ("SIRA_NO", DOSYA_NO, PROTOKOL_NO, "SEVK_ICD")
  PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
  TABLESPACE USERS,

MAKBUZ_D_NO,--rows I want to delete
  CREATE INDEX "HASTANE"."MAKBUZ_D_NO" ON "HASTANE"."MAKBUZMAIN" (DOSYA_NO, PROTOKOL_NO)
  PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE
0
i need to enter IP's in regex format in my claim rule on my ADFS server

is there any way to do
0
I need regular expression that will check if the value is a whole number and greater than 0.  

Data
---------------
120                     ------>    TRUE
 0                        ------->    FALSE
-2                       --------->  FALSE
N/A                    ---------> FALSE
[NULL]              ----------> FALSE
1                        ----------> TRUE
3.00                  -----------> FALSE
3 IN                   -----------> FALSE
0
I need a regular expression that will check if a string contains words "Wall Mount"  and ("Inwall or "in-wall" or "in wall").  

Data
-------------------------------------------------


Wall Mount (Inwall Frame/Plate)                 Match
Wall (Inwall)                                                     Not Matched
Wall Mount (In-Wall)                                      Match
Wall Mount InWall                                         Match
In Wall MNT                                                    Not Match
IN-WALL  (WALL Mount)                              Match
0
I need a regular expression that can search for a "/" within "( )".  

Data

Wall-Mount (InWall / Plate)    = True
Wall/Mount (test)                     = Not True
Wall-Mount  (test)                    = Not True
(1/2) Test                                   = True
(Test, Test/TEST) 123               = True
/Test                                           = Not True
/Test/                                         = Not True
(/Test Abc                                  = Not True - No closing ")"
0
Become a Microsoft Certified Solutions Expert
LVL 13
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Is there anyway to make "cmpid" , which is the name in the name/value pair we want in the query string, case insensitive in the logic below?
    var decodeURL = decodeURIComponent(campURL);//full URL
    var cmpidValue = decodeURIComponent((new RegExp('[?|&]' + 'cmpid' + '=' + '([^&;]+?)(&|#|;|$)').exec(decodeURL) || [, ""])[1].replace(/\+/g, '%20')) || null;

Open in new window

0
I'm trying to extract an integer/decimal out of a string using a regular expression. The variations I've tried haven't worked. I thought to add a check on the string after the value I need would do it, but I'm just not writing the regular expression right.

Could some help me?

The string's I'm dealing with are:
CALL IBM  05/10/19  1500.23TOM & JERRY
PUT APP  05/10/19  182BOB & SALLY

Return:
1500.23
182
0
Hi Expert's,
For remove multiple spaces in a string I use this code:
$var = preg_replace('/\s+/', ' ',$var);

Open in new window

What changes I have to do in the code, but for remove multiple hyphens?
Examples: this-is---a--test, convert to this-is-a-test;
this is a ---- test, convert to this is a - test;

The best regards,
JC
0
i need help with a regular expression to identify a "/" with a number preceding and number following.  Basically, I am trying to identify fractions.  

Data Examples:
1-1/4 in       --> Yes, fraction
1 3/4           ---> Yes, fraction
3.400           -->  No, not a fraction
W/4 new     -->  No, not a fraction
1- /6            ---> No, not a fraction
4/5 Feet      ---> Yes, fraction
0/0               --> Yes, fraction
0
Greeting Experts,

I am new to writing "regex expressions" and need help creating some search patterns related to keywords (i.e. HR, SSN, Social Security Numbers, etc). Can somebody help me with this task if possible...
0
I need a regular expression to find strings like this:  

ElectriFLEX LD(TM)
(RR) Flex Seal
0
Hi bash experts.

Could you kindly help with this please.

  1. Have a json file which I would like to automate replacing some values.
  2. Value would come from a property file.
  3. I'm trying to avoid introducing a token in the source json file and use sed to replace it.
  4. Would really like to check for name and then replace value portion, may be sed will use regex
  5. Since I dont have control on the file, I prefer this.
  6. Very worst case I can introudce tocken and use sed to replace if that is safe and simple


Have attached
  1. json file (before)
  2. json file (after)
  3. sample property file

Thanks in advance
config_after.json
config_before.json
sample.properties
0
Hi,

I have a regular expression that is currently being used to enforce 8 characters etc. however, I would also like to prevent the user from entering the word 'password', is this possible to add in this regex expression?

^(?=.*[A-Z])(?=.*[a-z])(?=.*[\d])(?=.*[\!\£\$\%\^\@\#\~]).{8,}$

Open in new window


Any help is appreciated.

Thanks
0
Hi
in the code bellow I'm trying to remove 1080p | HD either in or out of ()
I butl the using regexq101
this appears to work except for last witespace
however I'm not getting the expacted reults


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Text.RegularExpressions;

namespace Remove1080p
{
    class Program
    {
        static void Main(string[] args)
        {
            string Root = "";
            Console.WriteLine(@"Drag folder");
            string Ans = Console.ReadLine();
            if (Ans == "")
            {
                Console.WriteLine("Need a folder");

                Console.WriteLine(@"Drag folder");
                Ans = Console.ReadLine();
            }
            if (Ans != "")
            {
                Root = Ans;
                if (Root.EndsWith(@""""))
                {
                    Root = Root.Trim(new char[] { '"' });
                    Console.WriteLine("trimed " + Root);
                }
            }
            Regex regex = new Regex(@"(\s+(\(1080p\s+HD\))|(\(1080p\)|(\(regex\))|1080p|720p|HD)\s+)");

            string[] Files = Directory.GetFiles(Root);
            foreach (string file in Files)
            {
                Console.WriteLine("File " + file);
                FileInfo fi = new FileInfo(file);
                string Ext = fi.Extension;

              

Open in new window

0
JavaScript Best Practices
LVL 13
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

I need a regular expression that will check a string that contains only ALPH characters (A-Z) and special characters.

Compliant
---------------
NA                     ---> Match
NA1234            ----> Not matched because has numbers
UN123             ----> Not matched because has numbers
23u                  ----> Not matched because has numbers
na                    -----> Match  
N/A                 ------> Match
n-A                  ------> Match
0
I need a regular expression that would check if a field contains any non-numeric values (i.e., alpha) and nulls.  

UPC
---------
N/A                        ---> Should match REGEX
123456789012    ---->Would not match REGEX
                              ----->Should Match Regex  (null or space)
---                          ---> Should match REGEX
0
Hi E's,
I need a Regular Expression because I'm developing an application for banking matters, and in this case, I have to check some tax rate.
The RE just validate if the first character is a number/numbers, a end point, and in the end number/numbers again, like this examples:
0.1
11.45
0.000
0.975

Can you please help me?

The best regards, JC
0
Hi E's,
I create this regular expression:
"^([0-9\u2098\s]*)$"
The objective is just allow the character M or m, and/or numbers from 0 to 9 (ex: m1; m99, 991, mMM10) , but unfortunately don't work.
What I do wrong?

The best regards,
JC
0
Hi E's.
I try to validate a string with javascript, that just allow alpha characters, like this:
function isAlpha(str) {
  var code, i, len;
  for (i = 0, len = str.length; i < len; i++) {
    code = str.charCodeAt(i);
    if (!(code > 64 && code < 91) && // upper alpha (A-Z)
        !(code == 32) &&
        !(code > 96 && code < 123)) { // lower alpha (a-z)
      return false;
    }
  }
  return true;
};

Open in new window

The problem is, if the string is "joao cacador", the function return TRUE, but if I use the string "joão caçador" return FALSE.
What changes I have to do in my function for accept also characters like: "´`ç^~" (usually used in Portuguese names, like João, Caçador, etc).

The best regards,
JC
0
Assuming a table row, how can I switch out a value for another throughout all the elements contained within that row id, name, class, ...

To simplify the example, I have a value of format

w-x-y-z

where w & z are constant and know, but the x & y are wrong.  Now I can determine the proper x & y, but need to now update value throughout all the row elements wherever it may be used (I know it is used in id, name, class).

Here's a concrete example

<tr class="item-phone">
	<td style="width: 25px;">
		<button type="button" class="remove-phone btn btn-danger btn-xs table-control">
			<i class="glyphicon glyphicon-minus"></i>
		</button>
	</td>
	<td style="width: 225px;">
		<div class="table-control field-clientscontactsphones-0-0-phone required has-error">
			<input type="text" id="clientscontactsphones-0-0-phone" class="form-control" name="ClientsContactsPhones[0][0][Phone]" aria-invalid="true">
			<div class="help-block"></div>
		</div>
	</td>
	<td style="width: 60px;">
		<div class="table-control field-clientscontactsphones-0-0-phoneext">
			<input type="text" id="clientscontactsphones-0-0-phoneext" class="form-control" name="ClientsContactsPhones[0][0][PhoneExt]">
			<div class="help-block"></div>
		</div>
	</td>
	<td style="width: 175px;">
		<div class="table-control field-clientscontactsphones-0-0-phonetypeid">
			<select id="clientscontactsphones-0-0-phonetypeid" class="form-control" name="ClientsContactsPhones[0][0][PhoneTypeId]">
				<option 

Open in new window

1

Regular Expressions

A regular expression ("regex") is a sequence of characters that define a search pattern, mainly for use in pattern matching with strings, or string matching, i.e. "find and replace"-like operations. Regular expression processors are found in several search engines, search and replace dialogs of several word processors and text editors, and in the command lines of text processing utilities, such as sed and AWK. Many programming languages provide regular expression capabilities, some built-in, for example Perl, JavaScript, Ruby, AWK, and Tcl, and others via a standard library, for example .NET languages, Java, Python and C++ (since C++11). Most other languages offer regular expressions via a library.