[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

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
Become a Microsoft Certified Solutions Expert
LVL 12
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).

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
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 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
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
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
Bootstrap 4: Exploring New Features
LVL 12
Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

Hello,

I've many connection strings in web.config which I need to replace with different values. Please find below three types i.e. name = "DBString1", "DBString2" & "DBString3"Please note, "DBString2"


<add name="DBString1" connectionString="server=servername;database=DBName;user id=userid;password=password;Application Name=Web:TestApp" providerName="System.Data.SqlClient"/>


<add name="DBString2" connectionString="Data Source=servername2;Initial Catalog=DBName2;uid=userid2;pwd=password2;Application Name=Web:TestApp" providerName="System.Data.SqlClient"/>


<add name="DBString3" connectionString="server=servername3;database=DBName3;user id=userid3;password=password3;Application Name=Web:TestApp" providerName="System.Data.SqlClient"/>

Best Regards
0
Hi Folks,

Could you assist me to generate regular expression to change web.config connection string?
For example, below "DBString", I need to make change in server, user id, password like servername, userid password values respectively
<add name="DBString" connectionString="server=servername;database=DBName;user id=userid;password=password;Application Name=Web:TestApp" providerName="System.Data.SqlClient"/>

Open in new window


Could you assist into it?

Best Regards
0
Need help with regular expression to fin a words after a match string.   I need to find all the word after "KW".    For example;

Wiring Config
-------------------
54KW208V             --->  Need to find 208V
64kw
300KW c               ----->  Need to find  c
0
I'm trying to get the op numbers from the following filename strings using RexEx which the pattern will be used in VS2017 using the C# language for developing a Windows Form Application. In this application, we are filtering filenames in a datagridview by Op number when searching through a folder directory and all its subdirectories. I'm having an issue trying to get the regex to work on the tester websites I have tried. These are regxr.com and regexstorm.net/tester

Filename1: C-2590-3 REV-B OP#50.pcl
Filename 2: C-2590-3 REV-B OP#50-59.pcl
Filename 3: C-2590-3 REV-B OP#50-59-90.pcl
Filename 4: C-2590-3 REV-B OP#50-59-90-70(Flip).pcl
Filename 5: C-2590-3 REV-B OP#50-59-90 (Flip)60-90.pcl

The text I need to capture is :

Filename 1 Results: 50
Filename 2 Results: 50-59
Filename 3 Results: 50-59-90
Filename 4 Results: 50-59-90-70
Filename 5 Results: 50-59-90 60-90

This is what I have tried on the regexr.com tester:

(?<=\043)\d{2}|(?<=\043)\d{2}.\d{2}|(?<=\043)\d{2}.\d{2}.\d{2}

(?<=#)\d{2,}|(?<=#)\d{2,}.\d{2,}|(?<=#)\d{2,}.\d{2,}.\d{2,}

and I keep getting stuck because it will only show me the 1st two digits "50"

I'm not real familiar with Regex and I thought I should get some help because I'm missing something And don't know what that might be.

Can anyone help with this? Here is a screenshot of the form application running.

Tesa File Search - Screenshot1
0
Hi, everybody!

I have an annoying challenge where I have Excel data like

"Projection packages range from $200-$350" or
"$31.22 per user ($1,561 flat rate) Dedicated Bandwidth for 50" or
"12% added to F&B, 10% added to all meeting room rental charges"

in cells in worksheets containing property information, and I'd like to try to create a UDF that will pull out the 1st instance of a number out of the string in these cells (or, alternatively, if a UDF is not possible, just a regular sub).

Thus, something like "Projection packages range from $200-$350" would convert to 200,
"$31.22 per user ($1,561 flat rate) Dedicated Bandwidth for 50" would convert to 31.22
"12% added to F&B, 10% added to all meeting room rental charges" would convert to 12

Thanks for any help you can provide.

Best,

-doctornick0
0
Need help with a regular expression.   Just need a REGX to match on multiple words.  I need to find words "Gas, Propane (LP)" or "Gas, Natural".  

Source File - Fuel Type     Regex Match Results
--------------------------------     ----------------------------
Gas, Propane (LP)             Gas, Propane (LP)
Gas, Natural                      Gas, Natural
Electric
Gas                                      
Gas, Propane                    Gas, Propane
123  
Propane
Gas Natural                      Gas Natural  
Gas Propane (LP)            Gas Propane (LP)

thanks,
0
I have a table in a DB with a general text field which contains HTML formatted text. I need to parse the content of such a field, find all the "img" tags and perform 2 operations (only for "img" tags):

1) Remove completely the "style" attribute (if there is one).
2) Add a class="img-responsive" attribute.

For example, a simple string to be parse can be as follows:

<div>
<p>This is some text</p>
<img src="http://www.mywebsite.com/myImage.jpg" alt = "" style="width:600px; height: 400px;"/>
</div>

Open in new window


Or, something more complex:

<p style="margin: 0px 0px 10px; background: white; font-size: 14.6667px; font-family: Calibri, sans-serif;"><span style="font-size: 14pt; font-family: Georgia, serif; color: #404040;">
<img src="http://www.mywebsite.com/myImage.jpg" alt="" style="width:600px; height: 898px;" />
<br /></span></p>  

Open in new window


In both cases, the "img" tag should result in:

<img src="http://www.mywebsite.com/myImage.jpg" alt="" class="img-responsive" />

Open in new window


I know that one option is to use regular expressions but I do not have any experience with them. I will be using C# to perform this task.
I will very much appreciate your help.

Respectfully,
Jorge Maldonado
0
What would the JS regex be to test if a string had "business" and optional "qa" followed by a period? So both the below would pass?

businessqa.bank.com
business.bank.com
1
I need some regex help. I am currently using the following regex "^(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z])(?=.*[^a-zA-Z])\S{8,20}$" (without the quotes) to validate a password that would require an upper, lower and non-alpha character. I need regex to meet the following criteria:

The password contains characters from three of the following categories:

Uppercase letters
Lowercase letters
Base 10 digits (0 through 9)
Non-alphanumeric characters (special characters): (~!@#$%^&*_-+=`|\(){}[]:;"'<>,.?/) Currency symbols such as the Euro or British Pound are not counted as special characters for this policy setting.
Any Unicode character that is categorized as an alphabetic character but is not uppercase or lowercase. This includes Unicode characters from Asian languages.
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.

Dear Experts

I am trying to find software - optimally free, which would allow me to play with regular expression in a way, that from current set of found capturing groups I would be able to setup new text, copy it and paste where I need.

Simply example:

I have 2 lines of text taken from somewhere (copied) and pasted into Regular expression software:
2018-09-18 Hash XY
2019-01-17 Hash AB


In search field I would search for (\d\d\d\d)-(\d\d)-(\d\d)

And somewhere in 3rd window I wanted to enter %3-%2-%1

Which would give me
18-09-2018
17-01-2019

Do you have any idea?

Thanks

Vladimir
1
Hi there, I need a regex expression to extract a uk phone number from a string.
This is with a view to detecting phone numbers in paragraphs of text.
There are plenty of examples out there to verify UK phone numbers as being a regex match but I cannot find anything which will do so returning the match from within a string.
Uk phone numbers are 10 or 11  numbers long with a 0 at the beginning.  

This regex is an example of a regex which matches a phone number, but cannot handle leading or trailing text.  Can somebody help perhaps in modifying it so it can still pick out the numbers in a string whilst ignoring leading/trailing text.  

^(((\+44\s?\d{4}|\(?0\d{4}\)?)\s?\d{3}\s?\d{3})|((\+44\s?\d{3}|\(?0\d{3}\)?)\s?\d{3}\s?\d{4})|((\+44\s?\d{2}|\(?0\d{2}\)?)\s?\d{4}\s?\d{4}))(\s?\#(\d{4}|\d{3}))?$

Open in new window


Thanks,
0
How to have textbox regular expression validation on asp.net?


I will have to allow 3 digits and units in the text box. Decimal units should not exceed more than 2 units.

How to handle that?
0
I'm looking for a  Javascript regx that will detect a-z (case insensitive)  or 09 as a group and then a hyphen followed by any group  of a-z or 09  etc. Always will start/end with (a-z or 09) For example:

a12dd3-23-fff-11n3N33n3-988
9fkr-rtt488-344-45
r5999999Rrp-4-yei388dfi3-3444-fjj577-23
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
1234-567-8-922-222222-2-1111
0
From the following extract from a source input stream, i need to use c# regex to extract a match collection of each matching block of code between the ##if WORD ## and the matching ##endif WORD ##

##if textbox ##
		<tr>
			<td>Textbox description here, could be anything:</td>
			<td>##textbox##</td>
		</tr>
##endif textbox ##
		<tr>
			<td>multilinetextbox</td>
			<td>##multilinetextbox##</td>
		</tr>
##if staticdropdown ##
		<tr>
			<td>staticdropdown description here, could be anything or nothing or something else alltogether:</td>
			<td>##staticdropdown##</td>
		</tr>
##endif staticdropdown ##

Open in new window


The returned match should include the ##if and end ##endif blocks as below...

Match 1:
##if textbox ##
		<tr>
			<td>Textbox description here, could be anything:</td>
			<td>##textbox##</td>
		</tr>
##endif textbox ##

Open in new window


Match 2:
##if staticdropdown ##
		<tr>
			<td>staticdropdown description here, could be anything or nothing or something else alltogether:</td>
			<td>##staticdropdown##</td>
		</tr>
##endif staticdropdown ##

Open in new window


I have been testing various online regex testing sites to see I I can get what I need but always end up with the match being from the very first ## if WORD ## to the very last ##endif OTHERWORD ## construct

Any help gladly accepted :D
0
Regex Destination url needs to be lower case.  I found this code that will convert it to lower case in the httpd.conf file.

RewriteMap lc int:tolower
RewriteRule (.*?[A-Z]+.*) ${lc:$1} [R]

Open in new window


Here is a sample url

http://www.theherbsplace.com/Garlic_Oil_Capsules_p_400.html

Open in new window

source url

https://www.theherbsplace.com/product/garlic_oil_capsules_p_400/

Open in new window

target url

I need to know if there is a better way to do this.  Because it seems very slow on Xampp.
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.