[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x

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

Hi,
I'm fairly new to php and mysql but I'm creating a PHP and MySQL web application for a client. I have a register.php page with the following form fields:
Contact Name, Phone, Email, Password, Confirm Password, Ticket Holder Password and Ticket Holder Confirm Password, where Users can register/sign up to use the app. Once they do register, they get redirected to admin_login.php page where they can login and get full access to the app and various other pages I've created.

My Problem:
My Password validation functions aren't working and I'm not sure why. I want the passwords to be a minimum of 8 characters, contain one upper and lowercase letter, a number and a special character. I'm using a regular expressions code that I found online. What I want is to validate the Password fields, so if the User enters a password that meets the criteria mentioned above than it should INSERT the data INTO the database, if it doesn't meet the Password criteria mentioned above I want to display an error message saying: "Password must be minimum of 8 characters, contain one upper and lowercase letter, a  number and a special character". I'm new to using php functions and how to call them properly.

This is the code in my functions.php page:

<?php

// FUNCTIONS.php

// clean the form data to prevent injections

/* Built in functions used:
   trim()
   stripcslashes()
   htmlspecialchars()
   strip_tags()
   str_replace()
*/

function validateFormData($formData) {

Open in new window

0
Starting with Angular 5
LVL 12
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

Hello,

I'm using Notepad++ to test some REGEX against a csv file.  

I've got a string that seems to be correctly identifying the first instance of a space followed by an upper case letter in each row of the file:

(^.*?)\s[A-Z]

The next step would be to insert a pipe symbol just before the uppercase letter.

So given a line like this:
XAb(2)-AB SOME UPPERCASE TEXT | SOME OTHER STUFF | AND MORE STUFF

The REGEX would replace the pattern with:
XAb(2)-AB |SOME UPPERCASE TEXT | SOME OTHER STUFF | AND MORE STUFF

Any help will be greatly appreciated!
0
Hi,

I want to know if there is a way that I can test the regex online that are created for Keyword Highlighting in SecureCRT. Below is the sample regex entries that I want to test and modify as per my requirement.

 "[*]For_Best_Results:_Set_Forground_Font_To_Gray_(Not_Black!)"
 "[*]Gray_Keywords_Are_To_Work_Around_Symbol_Delimited_Words"
 "[*]Special_Cases_That_Had_To_Be_ReOrderd"
 ".*'.*"
 "on-fail.*
 "[*]In_Enable_Mode"
 "^\w[^>]*#|hostname"
 "[*]NOT_In_Enable_mode"
 "^\w[^#]*>"
 "[*]Interfaces"
 "Embedded-Service-Engine\d\/\d"
 ".*thernet[0-9]+(?:[\/\.:][0-9]+)+[,:]?(?:\x20|$)"
 ".*thernet[0-9]+[,:]?(?:\x20|$)"
 "\b[efgt][a-z]*[0-9]+(?:[\/.:][0-9]+)+[,:*]?(?:\x20|$)"

Open in new window

1
I need a regular expression that will identify values that end with a plus sign.  I have a column that contains multiple weights in some cases and when it does I just need to extract the second value.  For example:

Values
607+800 lb    --> I need to identify the 607+ and remove.
822 + 44 lb    --> I need to identify the 822 + and remove.
555 lb
100 lb
0
I need a regular expression to check for a word in a string that has a "/".  

Value
---------
40005 Btu/h    ---->  I need to detect if the value has "Btu/h"
5009 BTU/H    ---->  I need to detect if the value has "BTU/H"
6999 BTU        -----> I also need to detect if value has just "BTU".
6700
900000 Btu
0
I need help with a regular expression that will check a column for a certain word, blanks and all white space.  I need a regx to check If the column below contains the word "NULL" or "Null" or  is blank or contains just white space.  

Description
----------------
NULL                  ------> If the column contains the word NULL.  
Plates
                             ----> White space example.  
Cups
Napkins and Cups
                           ------> Blank example
0
Experts,

Using C# I need to pull a date out of a string. The date format will always be numbers in day/month/year style. Of course the day and months could be 1 or 2 digits each, the years are always 4 digit. I've been reading about regex's but i can't seem to get it right. The string contains lots of words in addition to the date. The date always has at least one space leading and trailing it.
Example: "Here we 7/15/1957           down the path"

Thanks!
0
Hello,

I have over 100 CSV files that I need to pre-process before importing to SQL.  The files are too large to open in Excel.

What I'm trying to do is modify the first line (the header row) of each file to add double-quotes to the field terminators.

For example, given this header row:
field1|field2|field3|field4

replace | with "|" so the first row would be:
field1"|"field2"|"field3"|"field4

Notepad++ has a "find in files" feature that can use regex but I'm not sure how to linit it to the first line.

Any ideas would be greatly appreciated.  

Thanks!
0
I need to delete a block of text that is on 400 pages of my mysql db.  It is in wp_posts and the post_content section.

This is the block of code
<p><span class="heading">Product Label</span> - <span style="color: #909;"> Place your mouse cursor over the image to zoom in to read the label. </span></p> <p><img src="/Resources/labels/3538.jpg" alt="Product Label" /><br /><br /></p> 

Open in new window


This block is the same for all pages with the exception of the number specifying the .jpg

This is the sql I created but it isn't working even without the regex.

SELECT * FROM `wp_posts` WHERE (post_content LIKE '%<p><span class="heading">Product Label</span> - <span style="color: #909;"> Place your mouse cursor over the image to zoom in to read the label. </span></p> <p><img src="/Resources/labels/3538.jpg" alt="Product Label" /><br /><br /></p>%'); 

Open in new window


Please help me to create a query that will work for all numbered jpg's and just remove the block and replace it with nothing.

Thanks,
0
Hello,
I'm trying to clean a pipe delimited text file in notepad++ (or any other tool that would do the job quickly).  

Here's an example of the file layout:

col1|col2|col3|                                                             [cr][lf]
"value"|"vlaue"|"value"|                                             [cr][lf]
"value"|"vaaaalue"|"vaaaalue"|                                [cr][lf]


What I hope I conveyed visually is:
  • the file has a "faux" column after col3
  • there are varying lengths of white space between the carriage return and line feed of each row
  • the values in each column are of varying lengths

For each line I would like to remove the last pipe and any whitespace between the last pipe and the CRLF.
I can open the file in Notepad++ which has a REGEX find/replace function but I"m not exactly sure how to compose the search.

The file is too large to open in Excel.  

Any help will be greatly appreciated.  

TIA!
0
Exploring SQL Server 2016: Fundamentals
LVL 12
Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.

I need to create some regex criteria to assist with a custom content filter in some eDiscovery software, to filter a 100 GB directory of data for any documents which contain a certain pattern of text to meet the criteria 9 characters long, first two characters any alpha (a-z), characters 3-8 any numeric characters, the final character any alpha (a-z). The alpha characters are likely to be uppercase but not always. Any sort of starting point will help as very new to regex
1
I am having a little trouble with regex. Here is what I want:

xxx123.xxx123@xxx123.xxx123 should be found
xxx123@xxx123.xxx123.xxx123 should be found
xxx123.xxx123.xxx123@xxx123 should be found

xxx123.xxx123@xxx123.no should not be found
xxx123.xxx123@xxx123.xxx123.com should not be found
xxx123.xxx123.xxx123@xxx123.xxx123.org should not be found

In other words I want to find all email adresses missing the the .no, .com, .it, .org, .net etc. end part.

I am sure it is simple, but I haven't quite figured it out, so I would really appreciate any help on this!

Thanks!

Brgds
IVer in Oslo
1
On my PC this location contains a bunch of XML files

C:\SmartCompletion\Backend\IBS.Core\Resources

I'd like to limit my search to **just** the Resources folder.

There is a particular tag inside these XML files that I want to look at and verify that it does NOT contain a certain attribute:

 <Layout mode="Complex" UsePurgeRestore="true" UseCopy="true">   //////////// this would not show up in the search results

UsePurgeRestore="true" or UsePurgeRestore="false"  must NOT be an attribute in the <Layout> tag

So this would be a match for my search:

<Layout mode="Complex" UseCopy="true">

or this:

  <Layout UseAssignment="true" mode="Complex"  EditNewView="vAssetPacksLines">


Can Visual Studio do this using Regular Expressions?

I would need the RegEx.  I'm too slow at it and I need this as fast as I can.

reg ex search

NOTE:  I am open to freeware tools that can do this kind of exclusionary search of file contents.  I have AgentRansack, for example.  I also have Notepad++.   Do either of those support RegEx searches?

Thank you!
0
What's the JS regex for the below where I can have "we" and then possibly some characters followed by ".bank.com?:


wedev.bank.com
weqa.bank.com
weuat.bank.com
westage.bank.com
we.bank.com

Thanks!
0
I have a long text that has this string$

.... value="variablechars" .....

or
.... value='varchars'....

I need to implement a regular expression in asp to extract these strings and create a list (each record with 2 items)

Once extracted I have no problem in creating the list in my database

the list

name1, value="str1"
name2, value="str2"
name3,value="str3"

name4,value='str4'
name5,value='str5'
name6,value='str5'

I extract email with this code (asp)

Set RegularExpressionObject = Server.CreateObject("VBScript.RegExp")
With RegularExpressionObject
 .Pattern = "[_a-zA-Z\d\-\.]+@[_a-zA-Z\d\-]+(\.[_a-zA-Z\d\-]+)+"
 .IgnoreCase = True
 .Global = True
 End With

 StringToSearch = blocks(x)
 set objMatches = RegularExpressionObject.Execute(StringToSearch)
 for each objMatch in objMatches
 email=objMatch.value
 next

Also extract  strings as

&nbsp;Actividad <br/>

I guess I am missing the Pattern

Example

<img src="image.png" />&nbsp;Actividad <br/><input type="text" readonly class="textboxif" style="width: 410px;" value="Name of activity" name="sector" id="sector"/></td><td>

Here the items would be

Actividad,Name of activity

I have many atrings that I have to extract the data from

Any ideas?
0
Hello,

I am trying to write a regular expression for a spam filter that checks for  @  appearing more than once in a string.

Reason :  there is a new type of file-less virus exploit that comes into our spam filter  with two email addresses in the FROM field.  The writers of the spam filter are working on producing a fix but in the meantime I want to write a rule which examines the FROM field and if it finds  more than 1 instance of  "@"  in the string that is the FROM field, then the rule will reject that email.

Thanks for any help on this.

M.
2
I need a Regex which can convert this character   to ' in PHP.
Looking forward for help.

Thanks
0
I need SED to replace a string across multiple ASCII text files based on a regex pattern.  These files are descriptions of EDI file formats with records described in this format:

E2EDPT2 {  DELIMITER="\x0a" }:
    E2EDPT2_SEGNAM		# Segment E2EDPT2
    E2EDPT2_MANDT
    E2EDPT2_DOCNUM
    E2EDPT2_SEGNUM
    E2EDPT2_PSGNUM
    E2EDPT2_HLEVEL
    E2EDPT2_TDLINE
    E2EDPT2_TDFORMAT
    rest[0:"^\x0a"]*
;

E2EDPT2_SEGNAM: STRINGA { LENGTH=30, DEFAULT="E2EDPT2001                    " };
E2EDPT2_MANDT: NSTRINGA { LENGTH=3 };
E2EDPT2_DOCNUM: STRINGA { LENGTH=16 };
E2EDPT2_SEGNUM: STRINGA { LENGTH=6 };
E2EDPT2_PSGNUM: STRINGA { LENGTH=6 };
E2EDPT2_HLEVEL: STRINGA { LENGTH=2 };
E2EDPT2_TDLINE: STRINGA { LENGTH=70, MISSVALUE="                                                                      " };
E2EDPT2_TDFORMAT: STRINGA { LENGTH=2, MISSVALUE="  " };

Open in new window


What I need to do is replace the occurrences of fields like "E2EDPT2_SEGNUM" above with plain "SEGNUM".  All record types will have this field and I want to lose the record name part leaving just the fieldname SEGNUM.  The recordname part will always begin with a fixed length "E2EDXXX-".  What is the correct regular expression to get this done?
0
Hi Experts,

I have a string like below:

input = Test_8234_and_2345_end

I'm trying to create a regex that targets only the first group of 4 digits (i.e 8234) in the above string but it returns none. Underscore ('-') may be/may not be there in the input. what is wrong with my below code.
REG_EXTRACT(input,'(\d+)',1)
0
Become a CompTIA Certified Healthcare IT Tech
LVL 12
Become a CompTIA Certified Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Hi,

I need some help with the PowerShell script modification below so that it can also show, which line number the search pattern showed up?

$FileType = '*.log'
$SearchPath = '\\PRODFS01-VM\Logs'
$SearchPattern = 'Error'
Get-ChildItem -Include $FileType -Recurse -Path $SearchPath | Select-String -Pattern $SearchPattern | Sort-Object -Unique -Property Path | Select-Object Path

Open in new window


I'm not the expert in RegEx, hence I am using the basic.

Thanks in advance.
0
Im trying to write a jQuery validation method, but having issues getting the RegEx to match up.

Im trying to match a 16 character string, which has to be uppercase.
First 5 characters need to be A-Z
Next 6 characters are numeric
Next 2 charachers are A-Z
Last 3 characters can be A-Z or 0-9

So I got the following regex statment:-
5[A-Z]6[0-9]2[A-Z]3[[A-Z]|[0-9]

However when I run it thought an online checker it says it has matched 8, where surely it should say its matched 1, I can then put into my jQuery to say if the match == 1 then its good else there is a problem.

Any ideas what Im doing wrong, or am I miss understanding something here?
0
Need some help with matching a word using regular expressions. this below is not matching.  Any help appreciated.

I am looking to match either
"Band:"
or
Band:
 

var pagesStr = content.GetElementsByTagName("SPAN")[18].InnerHtml;
                                    if (content != null && Regex.IsMatch(pagesStr, @"\^\[Band:\]\+\$"))
                                    {
0
Hi Team,

Need to make a change in the following regular expression so that it could allow character '/', currently it is not allowing it.

Regular Expression: "^[\\w\\d \\-().,\\xC0-\\xFF]+$"

Looking forward to hearing from you.
0
In both JavaScript and C#, I need RegEx (regular expression) syntax to replace

2018-10-22T19:52:38

With:

/Date(<<ticks>>)/

where <<ticks>> is the JavaScript equivalent of this C# code:

 private static double GetUnixEpoch(DateTime dateTime) {
            var unixTime = dateTime.ToUniversalTime() -
                new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);

            return unixTime.TotalMilliseconds;
        }

Open in new window



Given the example string:

{""CheckedInDate":null,"CheckedOutDate":"2018-10-22T19:52:38","ClosingComments":"   TK: sd sdafdsaf   TK: sadfdsafsd","CompanyInstancID":null}

Open in new window


The result would be:

{""CheckedInDate":null,"CheckedOutDate":"/Date(234320000)/","ClosingComments":"   TK: sd sdafdsaf   TK: sadfdsafsd","CompanyInstancID":null}

Open in new window

0
I need help writing a regular expression that can be used to extract 4 names from a text similar to the 2 examples pasted below. The first 3 names appear separated by commas, following the "Decided:.*Before" pattern. The last name appears after any number of characters, following the 3 names, but on a different line, that would also have the keyword "judge" (case insensitive) in it.

In the example 1 below, the first 3 names are:
DYK
SCHALL
REYNA

The fourth name is:
SCHALL

In the example 2, the first 3 names are:
MOORE, WALLACH, and STOLL.

The fourth name is:
WALLACH

Thank you, experts!


EXAMPLE 1
 Office, Patent Trial and Appeal Board in Nos.\nIPR2015-00343,     IPR2015-00345,     IPR2015-00347,\nIPR2015-00348.\n               ______________________\n\n              Decided: March 26, 2018\n              ______________________\n\n   DAN L. BAGATELL, Perkins Coie LLP, Hanover, NH,\nargued for appellant.   Also represented by ROBERT\nSWANSON, Washington, DC; ANDREW GISH, DOUGLAS R.\nNEMEC, Skadden, Arps, Slate, Meagher & Flom LLP, New\nYork, NY.\n\n   GREGORY S. DOVEL, Dovel & Luner, LLP, Santa\nMonica, CA, argued for appellee. Also represented by\nSEAN LUNER, MATTHAEUS MARTINO-WEINHARDT; JUNG\n\f2              GOOGLE LLC   v. NETWORK-1 TECHNOLOGIES, INC.\n\n\n\nSUK HAHM, CHARLES R. MACEDO, Amster Rothstein &\nEbenstein LLP, New York, NY.\n                

Open in new window

0

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.