Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

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

Hi Experts,

I want the Regular Expression to capture the text (let's call that <datName>) in front of the text ".DatabaseName",
then to add a new line starting with <datName>:

<datName>.Connect = gstrdbConnect

So where you find something like

<datName>.DatabaseName blah blah

you add a line:

<datName>.Connect =  = gstrdbConnect

So for example, if the unedited text is:

..........................
    datLoadGroups.DatabaseName = gdbLoads.Name 'strDataPath & "\loads.mdb"
..........................
    datElasticMaterials.DatabaseName = gdbLayers.Name 'strDataPath & "\layers.mdb"
..........................

Open in new window



The edited text should be:

..........................
    datLoadGroups.DatabaseName = gdbLoads.Name 'strDataPath & "\loads.mdb"
	datLoadGroups.Connect = gstrdbConnect
..........................
    datElasticMaterials.DatabaseName = gdbLayers.Name 'strDataPath & "\layers.mdb"
	datElasticMaterials.Connect = gstrdbConnect
..........................
	

Open in new window

Thanks,

Regards
Leigh
0
New benefit for Premium Members - Upgrade now!
LVL 10
New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Hi

Can anyone help me with the regex to highlight the section of a string including and after a set of characters.

For example for the string

Assfgghh./.../.../https://654321

I want to only extract

https://654321

The length and values following https:// vary in length and character types.

I am calling regex using Python.

Many thanks
0
Hi:

In Notepad ++ I want to search and replace a string 'ABC' (the single quotes are legit replacements) with :ABC, but seem to find that the editor isn't able to find the string 'ABC' , only finds ABC (no single quotes).

How do I get it ti find the ABC with single quotes? I tried "'ABC'" and ''ABC'' but no luck
0
I need a regex to force a date form field to be all caps with a dash and YYYY format, i.e. JAN-2017, FEB-2017, etc
0
I use word list updater2.7 for windows os and i want to fiilter this: https://pastebin.com/zzTSgCrM
to this: https://pastebin.com/VnMF6MCH
thank you
0
regex code to delete all email.ru:blah123 lines
e.g.:
john@yamiail.ru:ravecca
raimi@yahoo.uk:mam@123
ianos@mail.ru:ravini

output:
raimi@yahoo.uk:mam@123

i use Word List Updater 2.7 for windows 7
0
I need a gawk code to remove this type of duplicates:

john:john
mary:1234
sdfds:sadfsf
john:john
mary:1234

Open in new window

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
i have a huge txt file and i want to extract all words wich contains  --> @123
i have windows 7 and i use: Word List Updater 2.7 to filter my lists
0
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
[Webinar] How Hackers Steal Your Credentials
LVL 10
[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

We are witnesses that everyone is saying that our children shouldn't "play" with a technology because it is dangerous. This article is going to prove that they are wrong.
0
Is this regex a valid tester for MM/DD/YY? I'm assuming its going to miss leap year and 06/31, 08/31, etc.
'[0-1][0-9]/[0-3][0-9]/[0-2][0-9]'

Open in new window

0
I need to validate a date field with MM/DD/YY requirements using a regex within a cold fusion form.
0
Current code that's breaking is:

1:^(([\w\!#$%&'*+-/=?^_`{|}~;]+(?:\.[\w\-_]+)*@(?:[\w\-_]+\.)+[a-zA-Z]{2,7})[;]?)+$

Open in new window


error message:

"Error","ajp-bio-8012-exec-5","07/31/17","10:55:57",,"Invalid CFML construct found on line 214 at column 73.ColdFusion was looking at the following text:<p>\'</p><p>The CFML compiler was processing:<ul><li>An expression that began on line 214, column 69.<br>The expression might be missing an ending #, for example, #expr instead of #expr#.<li>The tag attribute pattern, on line 214, column 53.<li>A cfparam tag beginning on line 214, column 6.<li>A cfparam tag beginning on line 214, column 6.<li>A cfparam tag beginning on line 214, column 6.</ul> The specific sequence of files included or processed is: D:\inetpub\wwwroot\centralinv\central_inv_contr_verify.cfm, line: 214"

I'm guessing the # is throwing an issue and maybe the $ and ^ ... anyone have any ideas to get around the coding errors for those characters:
0
This is my current regex setup:

^(([\w\-_']+(?:\.[\w\-_]+)*@(?:[\w\-_]+\.)+[a-zA-Z]{2,7})[;]?)+$

Open in new window


I need one to allow for all of these: !#$%&'*+-/=?^_`{|}~;

^(([\w\-_']+(?:\.[\w\-_]+)*@(?:[\w\-_]+\.)+[a-zA-Z]{2,7})[;]?)+$

Open in new window


would this work:
^(([\w\!#$%&'*+-/=?^_`{|}~;]+(?:\.[\w\-_]+)*@(?:[\w\-_]+\.)+[a-zA-Z]{2,7})[;]?)+$

Open in new window

0
I'm using the following regex expression in c#.NET
   (?<![0-9])0+
It will remove leading zeros from each block of digits found and works just fine in c#.

Now, I need to do the same in Oracle sql. However, Oracle is not supporting negative lookbehind (<!)....
So, I need an alternative for
   select REGEXP_REPLACE('00AB00010', '(?<![0-9])0+') text from dual
The expected result in the above example is AB10.
0
Regular expression to accept emails w/ apostrophes ... current expression below:

^(([\w\-_]+(?:\.[\w\-_]+)*@(?:[\w\-_]+\.)+[a-zA-Z]{2,7})[;]?)+$

Open in new window

0
I need a simple REGULAR EXPRESSION that will find a specific list of numeric values.    For example;

LineByID
------------
3000
1000
3001
9991
8888

I need a regular expression that would only find values "3000" and "1000".
0
Form field validation for a date requirement to be: Current date on or after 10/01/2017 - cold fusion form

A new requirement for a form. I need to detect the date a form is being submitted to be the current date on or after 10/01/2017 in a cold fusion form.

The date won't be placed into the form field/s but I need to detect the date. This will be implemented on 10/01/2017 fyi. I'll need to set the code up to test say for today's date then once working set it up to detect 10/01/2017 for when it goes live.

Thanks for any help. I'll start researching the topic as I've never tried to work this type of code before. Current code for one of the fields is:

  <cfset errorMsg = ""> 
   	<cfif NOT refind("^[DdFfGgHhNnVv][A-Za-z0-9]{1,21}$", form.Contract_Number) AND NOT refind("^70[Zz]0[a-zA-Z0-9]{2}\d{2}[a-zA-Z][a-zA-Z0-9]{8}$", form.Contract_Number)>
	   <cfset errorMsg = "The Contract Number is required and can contain no more than 22 alphanumeric characters.,">
	</cfif>
	<cfset session.invoiceDataContr.errorString = errorMsg>

Open in new window

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!

The Task To try and recognise peoples names (mainly last names) in any Office files (Outlook, Word or Excel).  Basically I can reduce all these items to just a text string.  The reason that I would like to do this is that I want to add an item to the Office context menu when a name is clicked on with a right click of the mouse.

My research pretty much looks like this with respect to Regex;

StackOverflow Forum Question
StackOverflow question
StackOverflow question

I have also found this library and have set up an example with one of the regular expressions here.

Here is a link to my regex101 code with text.. You can see that I need to fix this for German Umlauts.

Reading up on human name recognition and Regex there are some people that do not think it is a great idea. I have therefore thought of the following set of steps which still involves Regex but should not miss any names.

1. Create a simple Regex that collects all words which start with a capital, is longer than 2 characters and only has alpha characters
2. …
0
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
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,

I have a case where I have lots of HTML pages with <a name="[x]"> tags without any closing </a> tags.

Is there a regex that will find those <a tags so I can remove them?

Thanks in advance,

Steve
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

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.