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

I need help with a regular expression.  I just need an expression that will find a string of words.   For example;

Before:                                            Expected Result
37"  (side to side)                           37"
1-1/2'  (yellow)                                1-1/2'

Just need an expression that will find any non-numeric character except " ' / and -.
0
Cloud Class® Course: C++ 11 Fundamentals
LVL 12
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

How do I find and replace to remove inside div child element, keeping everything (all <p>*</p>'s) .  some times their is just on p element, and sometimes alot.
link to regex101
<div class="expand_collapse section_box">
     <h2>Animal </h2>
     <div class="box_content">                        
          <div class="expand_collapse section_box">
              <h2>Agent Facing</h2>
               <div class="box_content">
                  <p><a href="/Brochure.pdf" target="_blank">Animal<br>(bully breeds &amp; bite history)</a></p>                                                   
              </div>
          </div>
          <div class="expand_collapse  section_box">
              <h2>Consumer Facing</h2>
              <div class="box_content">
                 <p>content</p>
              </div>
          </div>
       </div>
   </div>
   <!-- Next Product -->

Open in new window


I just want to remove:
 <div class="expand_collapse section_box">
      <h2>Agent Facing</h2>
       <div class="box_content">

Open in new window

and
                           </div>
                        </div>
                        <div class="expand_collapse  section_box">
                          <h2>Consumer Facing</h2>
                          <div class="box_content">
                            <p>content</p>
                          </div>
                        </div>

Open in new window

so keeping one or more of the 'P' elements inside the second div.box_content element.
I think I need to create a group for one or many p elements  (<p>.*</p>)  then replace with $1? So I keep the p's? (This does not work)
Can you provide a link to a resource to help me with regex as I do a lot of replaces/removals.

It would look like this when done.
<div class="expand_collapse section_box">
    <h2>Animal </h2>
     <div class="box_content">                        
         <p><a href="/Brochure.pdf" target="_blank">Animal<br>(bully breeds &amp; bite history)</a></p>
      </div>
</div>
<!-- Next Product -->

Open in new window


Thanks in advance.   I am not good with regex.
0
Help me to fetch first 3 lines of my email body by regular expression
0
Using Oracl regular expressions I want to extract character after the \

'OPS$BCTGTWDOM\SMANAVI'     Output => SMANAVI

How can I do this?

Thanks
0
Is there any machine learning algorithm using which we can detect/identify the articles from multiple news pages of any website.I tried it using Beautifulsoup/python fetching all links and processing it based on regular expressions but its taking much time.

Any help or suggestion will be much appreciated.
0
Hi there,
Is there a way/tool/ search engine that would allow me to search for multiple variations of the same phrase at the same time?
For example, I want to search for "revealing his true belief". But I also want to search for all the phrases that have the same or similar meaning like"betraying their real opinion".
The total number of words here is 8 but there are many different ways to combine the words so there are many different potential alternative phrases: "revealing his true opinion" "revealing his real opinion" "betraying our real opinion" etc….
Is there a way to accomplish this in two conditions?
1- I determine the alternatives. So I specify that for "word 1 word 2 word 3 word4", the alternatives for word 1 are: Only revealing or showing.
2- Use all the possible synonyms or even antonyms for "revealing" in word 1.
The tips I got so far from Reddit
"
Word2Vec or Doc2Vec is something that can be used for this, depending on whether you just wish to substitute synonyms or match the distributional semantics of arbitrary phrases.

---
If you don’t know your alternatives (e.g., you don’t know that revealing is similar to showing), then you need something than can do synonyms. Most search engines (e.g., Google) can do this, as can some natural language processing programs.

If you do know the alternatives, you can describe your pattern to a search engine or most computer programs using regular expressions. A regex that would match your example would be …
0
How would i get all child elements of a root element by class name using a regex pattern?

something like this

var items = $("#root_element_id").children("div:regex(class,\_[a-z0-9]{4})");
0
I have pattern "\A\bAbril\b[19]|([2]\d)\d{2}\z". The C# call I'm making is Regex.IsMatch(sInputPwd, @sPattern, RegexOptions.IgnoreCase). I only want it to match with passwords starting with AbrilYYYY (where YYYY is a 4 digit year) and with nothing appended but it's also matching passwords such as oneAbril2017, Abril2016two and even Ab2017 comes back as a match.
0
HttpWebResponse response = null;

                try { response = request.GetResponse() as HttpWebResponse; }

                catch (WebException) { return null; }



                // Regular expression for an HTML title

                string regex = @"(?<=<title.*>)([\s\S]*)(?=</title>)";

Open in new window


i want to understand what this do?
0
How to validate if a string has  a pattern  
(01)xxxxxxx(17)yyyyy(10) zzzzz(21)aaaaaa (30)bbb
where
xxxxx is a numeric digits with a fixed  length of 14 digits.
yyyyy is a numeric digits with a fixed length of 6 digits
zzzzz  is alphanumeric value with a variable length between 7-20 character (should allow special characters like  - , / . \)
aaaa  is alphanumeric value with a variable length between 8-20 character without any special characters
bbb is numeric digit with a fixed variable length upto 5 digiits.


I am using ASP.net vb program and want to use RegEx functions to validate a input string.

Can you share the validation criteria i need to use.

Thank you
0
Cloud Class® Course: Microsoft Windows 7 Basic
LVL 12
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

I am working with some folk who are using Expression Engine Version 2. something.  They are considering upgrading to the latest version.  I know that version 2 and version 3 have a different directory setup.  Is there any definitive docs on how to upgrade with minimal pain? Tutorials? Plugins? How to videos?  I'm in the exploratory phase of this project and will appreciate any input on upgrading EE from 2.... to 3.0 - 4.0 and beyond!
0
Can someone please help to create regular pattern in c using regex.h to match sub string without matching terminating . character.

For example, from below string pattern should match “hello world.” and “hello world” (there is no . char at the end of second match)

|hello world.|hello world.

Thanks for your input!
0
I need help to build regular expression pattern in c using regex.h. I have a string having pipe separated fields.

foo|this is first field.|this is second field.|this is third filed.

I have to create pattern at run time to  match complete field by sub string of it.  for example "second" will match  "this is second field." and "first" will match "this is first field." but "third" should match "this is third filed"  without including terminating . character.

If there are more then one . at the end then it should match them except last . character for example if third filed is "|this is third field..." then it should match "this is third field.."

can some one please help to create this pattern.
0
Hello,
I'm facing a great wall when dealing with regex expression which is supposed to filter email addresses with some exclusions of formatting of those email addresses

I need to apply a kind of standard regex expression
\b[!#\$%&amp;'\*\+\-\/=\?\^_`{\|}~a-zA-Z0-9][!#\$%&amp;'\*\+\-\/=\?\^_`{\|}~a-zA-Z0-9\.]*[!#\$%&amp;'\*\+\-\/=\?\^_`{\|}~a-zA-Z0-9]@[a-zA-Z0-9\-][a-zA-Z0-9\-\.]+[a-zA-Z0-9\-]\b

Open in new window

which would do:
### Include ###
anyvalidaddress@anyvalid.domain

### Exclude ###
<anyvalidaddress@anyvalid.domain
<anyvalidaddress@anyvalid.domain>
<mailto:anyvalidaddress@anyvalid.domain>

On purpose i didn't mention real email addresses, basically because regex should filter ANY valid email address in some way: include or exclude.

Updated 7:23:PM MSK 2/6/18
below is the text which as example needs to be processed
The phrase regular expressions <anyvalidaddress@anyvalid.domain (and consequently, regexes) is often used to mean the specific, <anyvalidaddress@anyvalid.domain> standard textual syntax (distinct from the mathematical $A12345@example.com notation described below) for representing patterns that matching text <mailto:anyvalidaddress@anyvalid.domain> need to conform Abc\@def@example.com to. Each character in a regular expression (that is, each character in the string describing its pattern) is understood to be a metacharacter (with its special meaning), or a regular character (with its literal meaning). For example,
in anyvalid.address@anyu.any.anyvalid.domain the regex a. a <anyvalid.address@anyu.any.anyvalid.domain is a literal character which matches just 'a' and . is a meta character which matches
0
How to truncate two range of numbers for example if the word document contains 748-769 text need to replace as 748-69 & other type p1231-p1239 change to p1231-9 and if the number is range 120-8 to expand as 120-128. Is it possible using select case in three type of above replacement in all range of numbers in word document. How it's possible in regex replace or any other way to replace?
0
I have a long text field in Salesforce form and using Regex to validate the duplicate entries.

For example my entries are - TESTP1, TESTP2, TESTP1,

I need a regex to identify the duplicate value TESTP1.

I need to use one regex expression to have this validated.
0
My regular expression for a valid URL with Port number is not working.  I need it to match:

www.test1.com:8080
https://www.test2.com:80
121.1.10.1:8080

thanks
0
Hi,

I'm trying to capture the text between the <soap:Header>.....</soap:Header> tags in one web service request and replace it into another request. I can capture the whole xml ok but having issues with the regex to extract out the content between the header tags. The error I'm getting is below

java.util.regex.PatternSyntaxException: Look-behind group does not have an obvious maximum length near index 37 (?= .*?(?= ) ^ error at line: 9

The regex I'm using is below but it is error as above

strRequest2 = strRequest2.replaceAll("(?<=<soap:Header>.*?(?=</soap:Header>)","Insert New Header");

The content between the header tags I'm capturing is quite long with a mix of characters and other elements

Any assistance in how to use regex capture the content between the two header tags and then regex to replace the content between another two header tags would be very appreciated

Thanks

Gavin
0
Can you change this so it uses and .oft as the email sent? I have attachments i want to send along with it.


' ExpertExchange Question ID 28492433
' http://www.experts-exchange.com/Software/Office_Productivity/Groupware/Outlook/Q_28492433.html
' Expert: ltlbearand3 [http://www.experts-exchange.com/M_2469312.html]
'
' -------------------------------------------------------------------------------
' MUST HAVE A REFERENCE TO:
'   Microsoft VBScript Regular Expressions 5.5
' -------------------------------------------------------------------------------

Sub CustomMailMessageRule(Item As Outlook.MailItem)
    Dim objRegEx As VBScript_RegExp_55.RegExp
    Dim colFoundWords As VBScript_RegExp_55.MatchCollection
    Dim objOutlookMsg As Outlook.MailItem
    Dim objOutlookRecip As Outlook.Recipient
   
    ' Set up Regular Expressions to search for the email Address
    Set objRegEx = New VBScript_RegExp_55.RegExp
   
    ' Search for Matching Email Addresses
    With objRegEx
        .IgnoreCase = True
        ' Set Global to False to only find the first instance as there could be more than one if they sent the email
        ' and it turned it into a link
        .Global = True
        ' This pattern will look for an email address - see http://www.regular-expressions.info/email.html if you want to know more
        .Pattern = "Email\sAddress:\s\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b"
        ' Run the Search
        Set colFoundWords = …
0
Cloud Class® Course: CompTIA Cloud+
LVL 12
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

What I am after is a regex that returns a value that is a suffix of:

Client #: 123456

Desired returned value is 123456
Is this possible?
2
I had this question after viewing adding leading zeros and trailing zeros.

I have the following:

C  --------------                                                                                                                                                                                    
P  IMAGE PANEL                                                                                                                                                                                        
C  --------------                                                                                                                                                                                    
C                                                                                                                                                                                                    
C                                                                                                                                                                                                    
C  ALIGN BOARD RECORDS :   # I need to match this pattern                                                                                                                                                                          
C                                                           …
0
My collection contain name attribute, which contains list of brand names.

db.brand.find({'name':{'$regex' : '^Apple?$', '$options' : 'i'}})

Open in new window


This query returns the Brand name 'Apple', but the fact ^ and $ is mentioned, shouldnt return the name 'Apple'. I.e., 'Apple' is not equal to 'Apple?'

Please let me know if we have any option in $regex to solve this ?
0
i have to process 100-200 gigs of text files in a day with 2gb each

currently my python code architecture is like:

def parsers(data):
    if (-----):
        regex_email(data)
    elif(----):
        regex_ip(data)
    elif(----):
        regex_url(data)

now i want to call multiple instances of parsers method at a time on different files with calling of regex methods in parallel.
0
Let say, I would like to find the wrapping point that make my code ugly. Please take a look on first pic
1.pngSo in the pic there is red square/ red cross, I mark the places in code what I wanna find to fix. So in general this is an "(" character + \n + " " " ( quote character ).
I know that it is possible to organize search ( shift + ctrl + f )  in intellij idea by using regular expression ( pic 2 ) but I don't know how to mix regular expression with comman one.
2.png
Please could you help me to write the needed search request for my code.
0
I'm used to working on a Linux server so .htaccess is familiar, but I'm having to do something on a Windows server and web.confg is throwing me for a bit of a loop. All I want to do is "prettify" the URL; for example, input something like /article&ID=5 into the URL bar and have it direct to index.cfm?p=article&ID=5. (The URL.p variable can be... well, variable, hence regex.)

Following is the code I'm using; /article will take me to index.cfm?p=article, but tossing on a query string will give me a "A potentially dangerous Request.Path value was detected from the client (&)." According to the documentation the query string should be appended by default, but I added appendQueryString="true" just in case and nothing changed.  Any ideas? Thanks!

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <httpErrors errorMode="Detailed" />
		<rewrite>
			<rules>
				<rule name="prettify" stopProcessing="true">
					<match url="^([_0-9a-z-]+)$" />
					<action type="Rewrite" url="/index.cfm?p={R:1}" appendQueryString="true" />
				</rule>
			</rules>
		</rewrite>
    </system.webServer>
</configuration>

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.