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 am looking for a regex that will catch things like;

gJ sKR Bow HRsT HRT BO KeT

In other words all 2, 3 or 4 letter characters where the word contains at least one capital.  Thus normal words such as

this, cat, ball etc

would not be found due to the capital rule.

I am do not know regex but doing a little bit or reading I think I have below 2 to 4 alpha characters but this allows them to be all lower case.
\b[A-Za-z]{2,4}\b

Open in new window


How can I change the above so that at least (meaning it could be more than one) one of the characters should be a capital.

Any regex will get me started but I am working in a .net environment.
0
On Demand Webinar: Networking for the Cloud Era
LVL 9
On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

I have a string of indeterminate length from which I wish to removed the Computer section using a regular expression.

1afrsComputer
3frs878Computer

Can anyone help please?
0
Hello,

1. Is it possible to write a regex that searches for a group of tags and finds the text regardless of whether or not a line break is there or not?

For example:

Can one regular expression find these two text samples:

<center>
<p><table bgColor="#e2dcc5" border="1" cellPadding="5" cellSpacing="0" width="475">
<tbody>
<tr>
<td>

and

<center><p><table bgColor="#e2dcc5" border="1" cellPadding="5" cellSpacing="0" width="475"><tbody>
<tr><td>

Thanks.
0
Hi Team,

I am having a text file having pipe separated string values. The issue is getting string within the string as shown below. I am looking for a regular expression or some solution to remove that quotes as shown in the desired text below.

Existing: "This string is ok."|"This is an example with a "C" double quoted grade in middle."|"Next line"
Desired: "This string is ok."|"This is an example with a C double quoted grade in middle."|"Next line"

Looking forward to hearing from you.
0
Hello,

I need a regular expression to find an HTML tag that contains a piece of text.

For example:

If I want to find any HTML tag that contains the text "tool", like:

 <img src="../global/Images/icons/tool.gif" alt="Tool" align="absbottom">

If would find the whole tag including its parameters.
0
I have a string AAABBCCCDEEEFF. I want to find out if any character in this sting repeats only 2 times. For example, AA or BB or CC etc. Also how to replace that char sequence in one regex? What is regex to identify this in java?
0
I have a bulk file that has multiple HL7 messages contained in the file.  Each message block starts with MSH segment.  However the batch file has index id numbers prepended to the string.  I need to remove the 10 characters before the 'MSH' and replace with blank.

I am using Notepad++ as the editor and I think this can be done possibly with regex but I don't know how to accomplish the task.  I have no regex experience, nor programming/scripting.

Thanks in advance for the assistance.

Current data example:
0000000764MSH|^~\&|RELAYHEALTH|RWJSL|RELAYHEALTH|RWJSL|20170622085225||ADT^A14|WIEH52WIJQQ7Q6JQVA7E|P|2.5
EVN|A14|20170622085225
...
0000000924MSH|^~\&|RELAYHEALTH|RWJSL|RELAYHEALTH|RWJSL|20170622091618||ADT^A14|TQSJB2CG9GTZH8SY8HWB|P|2.5
EVN|A14|20170622091618
...
0000000742MSH|^~\&|RELAYHEALTH|RWJSL|RELAYHEALTH|RWJSL|20170622091619||ADT^A14|EF0S0NGHIZLQGAYAMPT4|P|2.5
EVN|A14|20170622091619

Desired output would be:
MSH|^~\&|RELAYHEALTH|RWJSL|RELAYHEALTH|RWJSL|20170622085225||ADT^A14|WIEH52WIJQQ7Q6JQVA7E|P|2.5
EVN|A14|20170622085225
...
MSH|^~\&|RELAYHEALTH|RWJSL|RELAYHEALTH|RWJSL|20170622091618||ADT^A14|TQSJB2CG9GTZH8SY8HWB|P|2.5
EVN|A14|20170622091618
...
MSH|^~\&|RELAYHEALTH|RWJSL|RELAYHEALTH|RWJSL|20170622091619||ADT^A14|EF0S0NGHIZLQGAYAMPT4|P|2.5
EVN|A14|20170622091619
0
I want to keep all the lines that start with a + or a - but delete all other
lines in a file. I see a ready receipe for ^[+-]. that I could use to delete those
lines. But I want to keep them and delete all the ones. What's the mojo?
Thank you.
0
Hi Experts, how to pass (ignore) below line in regex. I'm  trying to achieve this in jenkins log parser plugin.

# Should pass
chmod: cannot access './config/temp_bkp_24072016/resources': Permission denied

# Should fail
chmod: cannot access './config/resources_bkp_24072016/resources': Permission denied

#regex rule. which I'm trying to handle above two scenario
warning /^(?!.*(temp_bkp))(.*Permission denied.*)$/

Open in new window



Thanks in advance
0
I have a situation where I need to be able to always highlight 3rd section or column of a string. Can anyone suggest the appropriate syntax?

For example in the below strings bird would be highlighted.

dog asds-sds-assa bird y

dinosaur nkj-as bird
0
Industry Leaders: We Want Your Opinion!
Industry Leaders: 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 regex function like this

^[0-9]\\d?-\\d{7}+;+([0-9]\\d?-\\d{7})*$

But I have a long text field where I enter multiple tax id numbers with semicolon. How to modify or allow this feature. Sometimes I only enter one tax id. How to handle this
0
is it possible to set up a regex to validate each position in a string of characters in a form field?

I have a requirement for a contract number field in a Cold Fusion form. Requirements are:

•      Positions 1-6 will be the  70Z0XX where XX is the contracting office code IE: 23.
•      Positions 7-8 will be the two digit Fiscal Year IE: 17.
•      Position 9 will be the one character instrument code IE: C, D, F.
•      Positions 10-17 will be agency assigned number.
•      New Example: 70Z02317D00000001

Is it possible to set up an expression at different points w/in the string of characters? I've never done that...only length requirements and forcing it to start w/ either a number or a letter. thanks for any help.
0
Hi,

I am in need of some assistance with a character search in any string for the followign characers

-
[
]
*
!

Any and all help would be very much appreciated.

Thanks

Simon
0
I am trying to gather all of the characters following the final space in a string but am struggling with the syntax. Can anyone help please? The last set of characters will always be alphanumeric but will be of differing characters and amount of characters.

 In the below example I would only want to highlight cat.  

 dog xxx-klsfkd-sdf-sdf cat


 And in the next one aaaaaaaaaaaaaddddddddddddddd

 heht ooijl-nanhjhsh aaaaaaaaaaaaaddddddddddddddd


however if the final character in the string is single I wish to ignore it e.g.

 heht ooijl-nanhjhsh aaaaaaaaaaaaaddddddddddddddd 0

would still highlight aaaaaaaaaaaaaddddddddddddddd


 Many Thanks
0
I am trying to gather all of the characters following the final space in a string but am struggling with the syntax. Can anyone help please? The last set of characters will always be alphanumeric but will be of differing characters and amount of charaters.

In the below example I would only want to highlight cat.  

dog xxx-klsfkd-sdf-sdf cat


And in the next one aaaaaaaaaaaaaddddddddddddddd

heht ooijl-nanhjhsh aaaaaaaaaaaaaddddddddddddddd


Many Thanks
0
Hi All,

Background:
I have written a script to grab the most common words in a page (with tags stripped etc.) It mostly works, however there is an occasional occurrence of the following happening: helloThisIsAnExampleOfTheAnomoly.

This occurs while grabbing certain HTML via a cURL based function, stripping tags and counting word frequency. It mostly appears to occur in menus and widgets.

What I'm looking for is an elegant/efficient solution to pop/push/unset values in the array with the values split.

To expand:
preg_replace('/(?<! )(?<!^)[A-Z]/',' $0', $words)

Open in new window


I'm using the above regular expressions to essentially split the values based on uppercase values occurring mid string/array element.

To summarise:
$array is currently something like this: ("This", "is", "okay", "this", "IsNotOkay")
What I want:
$array is going to look something like this ("This", "is", "okay", "this", "Is", "Not", "Okay")

Don't worry too much about the repeat values as I am utilising a "stop words" array to rid the ones I would not like to keep.

I've not got it working nicely yet so thought I'd turn to you for your expert input.

Thanks in advance.
Chris
0
I am looking to replace the value between two spaces in a string with a backslash. Can someone assist with the syntax.

E.G. I want

RED 123456789 White

to become

RED\White

Thanks
0
I am looking for a solution that uses CFSCRIPT to remove all text that is surrounded by '<style' and '/style>' including removing the style tags. Can someone show me how I can use something like ReReplaceNoCase to solve this.

For example: if I have text that looks like:

section a <style>here is style to remove</style>section b <style>more style to remove</style>section c

I need the function to return:
section a section b section c

Thank you.
0
I have a regular expression that does exactly what I want it to do but I don’t understand how it works.  I'm running a bash shell under MAC OS Sierra.

Here’s the command: sed -e 's/.*\"\(.*\)\"/\1/'

Here’s what it’s applied to: | "IOPlatformSerialNumber" = "QP93505K0TM"

which returns this: QP93505K0TM

which is exactly what I want.

The pattern match has two parts:

s/.*\”   and (.*\)\”

If I run just part one, it returns the entire string, which I expect because I read the first part to mean: “Match any string than ends with a quote”.

Part two always grabs the last part of the string.  I tested this:

“abc” “def” returns def

“abc” “def” “ghi” returns ghi

“abc” “def” “ghi” “jol” returns jul

My question is why does the expression enclosed in () always refer to the last part of the string?

Thanks.
0
[Live Webinar] The Cloud Skills Gap
LVL 4
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Can I use ReReplaceNoCase or someother javascript function to  remove everything in a string from and including '<style' to '/style>'? What would the function call look like?
0
Hi

I'm trying to create a template  using a REGEX rule to discard the last twenty four characters (" action=allow cache=MISS") of the following string when RSYSLOG receives notifications that contain the undesired sequence:
192.168.22.167 GET http://clients3.google.com/generate_204 action=allow cache=MISS

Open in new window

I can select the sequence using /( action=allow cache=MISS)/g but I can't find the solution to invert the selection in order to retain only the first part of the notification message
any ideas ?
thanks
yann
0
Hi I have a regex which works fine on

ABCDE123456X  - /LYBLA[0-9]{6}X/i (Fixed ABCDE, followed by 6 digits, and a fixed X.

I need to change this to be able to use a 7th digit instead of the final fixed X as well as the original format, for example

ABCDE1234567 and ABCDE987654X

Please advise
0
I have a form w/ several fields...one of the fields requirements states: The Contract Number is required and can contain no more than 22 alphanumeric characters. This can't contain spaces however:

here's the current regex setup:

	, Contract_Number: {
				required: true
			   ,pattern: /^[DdFfGgHhNnVv][A-Za-z0-9]*$/

Open in new window


Does anyone have any suggestions on how to modify this?
0
I need to pull two values from a repeating string. I've got it working 99% but it's ugly.

Looking for a trick here if you see one.

/******************************************
I got a simple solution, see comments
leaving here for any tips you might have
******************************************/

I am using REGEXP_COUNT to determine I have repeating strings, but that doesn't help me with the string manipulation.

Here's the data, it's a varchar2(600),
ATTENDED ECOLE NAVALE/FRANCE AS AN EXCHANGE STUDENT, SPRING '09
RECEIVED A LANGUAGE STUDY MINOR IN FRENCH
RECEIVED A LANGUAGE STUDY MINOR IN SPANISH

RECEIVED A LANGUAGE STUDY MINOR IN JAPANESE
RECEIVED A LANGUAGE STUDY MINOR IN CHINESE

ATTENDED NOVAMOVA, KIEV, FALL 2014 AS AN EXCHANGE STUDENT.
RECEIVED A LANGUAGE STUDY MINOR IN ARABIC. RECEIVED A LANGUAGE STUDY MINOR IN RUSSIAN.

RECEIVED A LANGUAGE STUDY MINOR IN RUSSIAN
RECEIVED A LANGUAGE STUDY MINOR IN SPANISH

RECEIVED A LANGUAGE STUDY MINOR IN ARABIC
RECEIVED A LANGUAGE STUDY MINOR IN SPANISH

For the first values, I get
FRENCH R
JAPANESE
ARABIC. R
RUSSIAN
ARABIC R

Here's my code -
The "9" is the length for the first value, to get the proper length would make this even uglier
The "+8" just points me in position to find the second value

Just showing how ugly it is. The only issue is getting the firs value cleanly.

     
substr(tn.notes, 
              -- find the position where the first minor starts
              

Open in new window

0
I want to match a url  such that it allows "abc.def.com" but not allow the following:
"abc.def.com/123"
"abc.def.com/456/789"

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.