[Last Call] Learn how to a build a cloud-first strategyRegister Now

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

I have the following regular expression:
^\s*<\s*script\s*name\s*=\s*["](?<name>[^"]*)["]\s* platform\s*=\s*["](?<platform>[^"]*)["]\s*(deferred\s*=\s*["](?<deferred>[^"]*)["])?>\s*$

Open in new window

It matches fine against the following:
<script name="FOO" platform="all">
<script name="FOO" platform="all" deferred="yes">
However, I need it to match regardless of the order of the parameters so it should also match:
<script name="FOO" deferred="yes" platform="all">
 -- and --
<script platform="all" deferred="yes" name="FOO">
How do I rewrite the above Regex so that it will match each name-value pair regardless of what order they appear?
0
Technology Partners: We Want Your Opinion!
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Given  the following code segments:
  lookupEvents={
    "/responsive/lead-form.":"event19",
    "checking-offer":"event29",
    "checking-offer-confirmation":"event32"
  };
...
 __.map(lookupEvents,function(value,key) {
            if(pathname.indexOf(key)!==-1) {returnValue.push(value);}
}

Open in new window


Is there a way to use a regX or other approach, possibly _filter, so both event29 and event32 are not set for URLs containing "checking-offer-confirmation"? I only want to set event32 for  "checking-offer-confirmation". I'm new to Underscore so not quiet sure how to handle this particular situation?

Thanks!
0
Basically, I want to return the matching FIRST pattern of 1 or 2 digits (as the day), 1 or 2 (digits as the month), 4 digits as the year separated by forwarding slash characters '/' from a valid or malformed input.

given these hypothetical inputs:

01/01/2017
1/1/2017/01/03/2017
1/1/2017/01/03/2017/a/b/z/0000
a/1/2/b/c/9/1/g/8/99/1/34/9/99/2017/z
ab/cd/efgh

I would like the output to be:
01/01/2017
1/1/2017
1/1/2017
9/99/2017
FALSE
0
Hi all.

I have several occurence of similar text in a very long email:

*1116 1200 ABC_Content_124853_124855 1117 1500
ABC_Content_123456_ABC_124865_Sound 1117 1000 - Documentation - 75% to 84% and 85% to 99%*

The text can change much but I am able to get all the relevant matches using this regex:
(?s).*\s(\*\d+\s+\d+.*?\*)+.*

The problem is that I can have many different occurencies of such group to extract and I'd need to implement it in Python.

Python says that (?s) is not a valid RegEx...

Therefore I've tried:
print re.findall(r'.*\s(\*\d+\s+\d+.*?\*)+.*', my_very_long_text.replace('\n', ' ').replace('\r', ''))

But I only print the LAST match and not ALL the matches.

Can you kindly help?
0
I'm using below code to translate power point text using VBA but im not able to maintain indentation when translated text is copied to the slide
please help . below code uses google translator UTF-8 format as translator.
i'm a newbie pls help
pls explain how regex is working here
thanks in advance



Sub TranslateKorToEng()
 
Dim selectedShape As Shape
Dim translateFrom As String, translateTo As String
Dim getParam As String, trans As String
Dim r As Integer, c As Integer, x As Long, y As Long
Dim groupCount As Integer, gg As Integer
 
translateFrom = "Kr" 'source language indication
translateTo = "en"  'result language indication
 
Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")  ' create object(shape,textframe,table) using HTTP format
 
If ActiveWindow.Selection.Type = ppSelectionText Then ' if only text is selected
    getParam = ConvertToGet(ActiveWindow.Selection.TextRange.Text)  ' replaces special symbols and applies text to convert to get function
    URL = "https://translate.google.pl/m?hl=" & translateFrom & "&sl=" & translateFrom & "&tl=" & translateTo & "&ie=UTF-8&prev=_m&q=" & getParam ' Creats and modifies the URL of UTF-8 translator with getparam
    objHTTP.Open "GET", URL, False 'open the http object
    objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" 'send command to browser
    objHTTP.send ("") ' send command
           
    If InStr(objHTTP.responseText, "div dir=""ltr""") > 0 …
0
for example:
Input is:
john\salima
rabadah.org\abc
silencio\123zzz

Open in new window


Output will be:
salima
abc
123zzz

Open in new window


i need a regex code for notepad++ or for wordlist updater 2.7
0
I need a JavaScript Regex to do the following:

Example 1 - String = '0:9,1:5,2:6,3:1'  
Example 2 - String = '5:8'

I want to return everything after the ':' and before the ','.

Example 1 result:
9
5
6
1

Example 2 result:
8

Thanks
0
regex code for notepad++ or for wordlist updater 2.7 please!

Input list:
john;salima;we;are;
not;me;

Open in new window


Output:
john
salima
we
are
not
me

Open in new window

0
I'm having trouble with the regex to find text in a string that is contained within brackets. The following works fine, except it's picking up unclosed bracketed text. I don't want it to match to anything that doesn't have a closing bracket.

Here's an example string:
[Match1] Here is some text. [Don't match this. [Match2]

I'm using the following regex:
/\[.*?\]/g

Open in new window


My regex is matching on the bracket in "[Don't match this". Can you help with correcting the Regex for this situation?

Here's the example on regex101.
0
Hi Experts,

My old nemesis, regex.  What i want to do is get a vm name out a string and replace it with a new name. When i'm renaming the VM i have to rename all the hard disks etc

e.g.

currentvm = vm1

c:\clusterstorage\vhd\VM1.vhdx
c:\clusterstorage\vhd\VM1-001.vhdx
c:\clusterstorage\vhd\VM1-002.vhdx

newvm = vm2

c:\clusterstorage\vhd\VM2.vhdx
c:\clusterstorage\vhd\VM2-001.vhdx
c:\clusterstorage\vhd\VM2-002.vhdx
0
Concerto Cloud for Software Providers & ISVs
LVL 5
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Hello Experts,

I could use some help with Regular Expressions. My problem is easy to explain:

Normally the pattern I am trying to match looks like this:

CASUALTY/INITIAL-17051/STBD FIN STAB OVERHEATS/EIC:TR00000/CAT:2//

The match syntax looks like this:
(CASUALTY.*\/.*)\/\/
Which returns:
CASUALTY/INITIAL-17051/STBD FIN STAB OVERHEATS/EIC:TR00000/CAT:2

The problem is that sometimes the message comes in with a VbCrLf somewhere in the string and it returns a null.

I tried to but \r\n in various places but nothing seems to work. Any assistance with this would be greatly appreciated!
0
I need a pattern string to edit a 10-character field having its first two characters equal to 'AA', 'AB' or 'AC', and the remaining eight characters numeric.  I don't know the RegEx "language", and don't know where to start.  Can anyone help?
0
Any way to write a query that will conditionally include a column?

I know that a Case statement can be used to control output, but
this is a little different.

For example, there is a column that contains some number of  1 character codes.
Let's say:   Optionscolumn  contains "ABCDEFG"

CASE WHEN Optionscolumn  like '%A%'  THEN 'yes' else ''  END  As ContainsA
CASE WHEN Optionscolumn  like '%B%'  THEN 'yes'  else ''  END  As ContainsB

That words just fine, but in the case of no value, I want no column at all included.
So, if   Optionscolumn  is not like '%A%'  then the column  "ContainsA" is not in the query results at all.

Reason is that there are over 30 possible values, and I only want to include the columns for
values found, which would be around 5 or 6.  I don't want 25 or so empty columns.

I've looked and tried, can't figure it out.

Since the columns needed would be different on different rows, maybe it's not possible, and
the only way is to  make a temp table and drop  any columns that are entirely empty?

Any thoughts?
Thanks!
0
I have created a form in html and images with radio button. For example in gender=>Male, instead of writing word Male, I have used a small male picture. I want this male picture to go in email when the user submits the form. I don't know if this can be done in php. Secondly I am a novice in php.

Please help me and all the thanks in advance.

Regards
Saxena
0
Is there any way to show interfaces on an IOS Cisco switch which only have x number of input errors? crc errors?

I tried to use "show int | i error" and that showed me lines with the word error but left me with no way to see with what interface the errors were associated.

Thank you.
0
Hello,

I need a reg ex that will find two pieces of text on the same line.

For example, I want lines where the text "fa-file-text" exists followed at some point by "default.asp"
0
This is nit picky type question, but I hope to learn something new about non-capturing patterns.

The following code extracts only 9 digit integers from a string.
An earlier version of the code had a simpler line 13:
     alternative:               msgbox onum

That version displayed e123456789 for the second number, because the non capturing portion of the pattern was still included as part of the match.    I wonder if there is some way to change the pattern to accomplish the same thing  so I could use the simpler alternative?  Something like a look behind?

Sub deletenow()
Dim regex, match, onum

    Set regex = CreateObject("vbscript.regexp")

    regex.Global = True
    '                                  / positive lookahead
    '                / non capturing  /
    regex.pattern = "(?:\D|\b)(\d{9})(?=\D|\b)"
    
    Set match = regex.Execute("1234 123456789 quote123456789 0123456789")
    For Each onum In match
        MsgBox onum.submatches(0)
    Next

End Sub

Open in new window

0
regex code to delete this lines: $HEX[

vipsa@7181
$HEX[6d65676164c3a17361]
$HEX[6c65796c61617964c4b16e]
irfan_1993_figo@hotmail.com
$HEX[31c2ba62616368696c6c6572]
$HEX[7365766563656e6dc4b1]
$HEX[6e657372696e736172c4b1]
askim_22_95
$HEX[d183d0bbd184d0bbd184d0bbd184]
roro.love.9
selimozel.1
chi1610@aj

Open in new window

0
Hi,

  I have a windows folder which contains a number of text files.
I need to find out a list of words starting TRP_     and ending in space, from all these documents.

Is there any way to achieve this?
Please help.
0
Free Tool: Site Down Detector
LVL 11
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Hi,
I have 2000 small HTML files and I want to replace something, or actuallr remove something.
I found EmEditor which I like a lot. It has some regular expression search. But I cant figure out how to solve my challange.

I have a piece of html code:
<a style="font-family:Arial; font-size:12px; " href="photo_send.php?id=???">Request high resolution photo</a><br>

very simple, I want to remove this line. However where you see ??? there are numbers in there from 1 to 2000. So I try to find a way to tell the find/replace to ignore on the find what is between the id= and the "

Any ideas on how to accomplish this?

Thank you for any tip.

Thom
0
Hello,

I need a regular expression that will find lines that:

1. begin with ResourceDescription
2. contain consecutive double quotes ("")

Thanks in advance!
0
I have a report that works with a regex and validates well enough w/ the regex. The client is asking to force the date field to be all caps though. I can add the style -  style="text-transform:uppercase" - to force this but when I do it throws an error. Anyone have any idea why this would happen? code below:
<cfinput type="text" 
                                          name="period" 
                                          validate="regex"
                                          pattern="^(JAN|FEB|MAR|APR|JUN|JUL|AUG|SEP|OCT|NOV|DEC)-(19|20)[0-9]{2}$" 
                                          message="Please enter the Accounting Period in the correct format, i.e. MON-YYYY." 
                                          required="true"
                                          id="period"
                                          class="Headline12DrkBlu" 
                                          size="10" 
                                          maxlength="8"
                                          default="#period#">

 But if you add the style to force the all caps it errors out: 

            <cfinput type="text" 
                                          style="text-transform:uppercase"
                                          name="period" 
                                          validate="regex"
                                          pattern="^(JAN|FEB|MAR|APR|JUN|JUL|AUG|SEP|OCT|NOV|DEC)-(19|20)[0-9]{2}$" 
                                          

Open in new window

0
Regexcode:Numbers, uppercase and/or Lowercase doesn't matter and which necessarily contains one or more of these symbols:

_!@#$%^&*.,?

I use word list updater 2.7 for windows os
thanx!
0
input file:

1 geani
1 mami
1 sally

output:
geani
mami
sally


i need a code for wordlist update2.7 , notepad can't help me the file is too big, thanks!
0
e.g.:

 brandon
   smich
marl
      siracusa
   sabine

Open in new window


output
brandon
smich
marl
siracusa
sabine

Open in new window


i use Word List Updater 2.7   for windows os
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.