Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

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

Regex matching _app_ and _app[X]_

input files:

898989_app_p99.pdf
353535X_appN_p99.pdf
575779X_appX_p99.pdf
524244X_appK_p99.pdf
0
Hire Technology Freelancers with Gigs
LVL 11
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Hi,

How to write regex expression for below string to get the final output as

"d1a2227e-291f-4d82-8991-b9458b4ad0d3","fb48e632-3c85-483b-86b3-76f7a1c7eb25","93fa5301-29e2-4ef6-9353-686868686888"



input string= @Check:"workspace://SpacesStore/d1a2227e-291f-4d82-8991-b9458b4ad0d3" OR @Check:"workspace://SpacesStore/fb48e632-3c85-483b-86b3-76f7a1c7eb25" OR @Check:"workspace://SpacesStore/93fa5301-29e2-4ef6-9353-686868686888
0
Hi Experts,

I'm feeling perplexed with trying to understand regex :(

- SC-EU-T-XXX01
- SC-US-T-XXX01
- SC-EU-S-XXX01
- VW-US-S-XXX01

- VWUPXXX01
- 85020-VWUPXXX01
- SCEPXXX01

From the above, i always want to get the text in square brackets

- [SC-EU-T]-XXX01
- [SC-US-T]-XXX01
- [SC-EU-S]-XXX01
- [VW-US-S]-XXX01

- [VWUP]XXX01
- [85020-VWUP]XXX01
- [SCEP]XXX01
0
I'm using the createobject("vbscript.regexp") object in a VBA environment.  I'm getting an extra, unexpected, match that I'd like to eliminate or understand.

pattern: (.*?)($|(?:&#\d+;))
string: Now 15 & $42.0 the time;  for all good# "men" -2 pet the dog cat horse 1,234.56

I'm getting the expected matches (submatch tuples):
("Now 15 & $42.0 the time;  for all good# ", """)
("men", """)
(" -2 pet the dog cat horse 1,234.56", "")

as well as this unexpected match:
("", "")

Why is this happening and is there a better pattern that will eliminate this extra match?
0
I have an editor that is putting in many  's in the source code it is creating.  I have been unable to stop the insertion of the strings but I do need them removed.

Here is an example
<tr><td align="left" style="color: #6e6f74; font-family: Arial, Helvetica, sans-serif; font-size: 14px; padding: 0px 0px 0px 10px; text-align: left;"><a href="http://www.theherbsplace.com/onsale" style="color: #5583c7;" target="_blank"><img alt="Nature's Sunshine" src="http://image.exct.net/lib/ff2c1c757166/i/4/096bf034-0.jpg" style="border: 0px; display: block;" /></a></td><td align="right" style="color: #6e6f74; font-family: Arial, Helvetica, sans-serif; font-size: 14px; padding: 0px;" valign="middle">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 

Open in new window

0
I am using Adobe Bridge to batch rename 130 files in a folder. It can handle regular expressions, so I am looking for the correct expression to achieve the following:

Original filename formats:
127155aaaa_58_Road to Cottage Lake Black.jpg
001000_Cottage Map.jpg

Description of revised filename:
Starting from left of entire filename -- Retain first 3 numbers of original filename
Starting from the left of '.jpg' file extension -- retain all text and spaces to left, up to and including the first instance of "_"
Retain ".jpg" file extension

Desired filename after batch renaming:
127_Road to Cottage Lake Black.jpg
001_Cottage Map.jpg

I hope I've provided enough details.

Thanks,
Andrea
0
i use this code: (.+?@(yahoo|xplorer|link).(?:ca|net|com))

results are:
asd@yahoo.com
asdsad@xplorer.ca
adas@earhtlink.net
asdsfsd@linkin.com


as you can see here appear: earthlink.net and also linkin.com  etc i want only @link.com
only that words MATCH CASE and not other extensions
0
i know how to filter: (.+?@yahoo.(?:ca|fr))
yahoo.ca
yahoo.fr


but how to filter more domains at the same time:
yahoo.ca
yahoo.com
xplorer.ca
xplorer.com
jazzera.ya
0
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
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
Independent Software Vendors: We Want Your Opinion
Independent Software Vendors: 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!

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
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
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 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
The timeslot format is HH:MM AM/PM - HH:MM AM/PM (example -   08:00AM-10:00AM) Need regular expression to validate this
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
Concerto's Cloud Advisory Services
LVL 5
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Hi folks!

I have spent some days looking for a regular expression which let me get order fields in a SQL SELECT statement.

Examples:

SELECT * FROM TABLE
ORDER BY A, B DESC, C

Open in new window


SELECT * FROM TABLE
ORDER 
BY A, 
B DESC, C

Open in new window


SELECT * FROM TABLE
ORDER 
BY A, 
B DESC, C LIMIT 100 OFFSET 4000

Open in new window


SELECT * FROM TABLE
ORDER 
BY A, 
B DESC, C 
ROWS 4000 TO 4100

Open in new window


For all these SQL sentences I wanna extract this:

A, B DESC, C

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
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

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.