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

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
[Webinar] Database Backup and Recovery
LVL 11
[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

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 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
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 need to extract email body from a MIME file using java regex. However, I would not be able to use any java library. I need a regex itself. If anyone knows, please let me know.
Thanks.
Shams
0
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
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 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
This regular expression solution below will cover part of the matching I am trying to do. What I am missing is matching for the double character options below.

A      AB      . . .      AZ
BA      BB      . . .      BZ
. . .      . . .      . . .      . . .
 ZA       ZB      . . .       ZZ


1:$tocheck='A9999';
2:print ((preg_match("/^[A-Z][1-9][0-9]{0,3}$/",$tocheck)==1)
3:or (preg_match("/^[1-9][0-9]{0,3}[A-Z]$/",$tocheck)==1));
0
how to split the below string using regular expression

ABCDEF234,SFRTG456,WER,TST890,TYUI111

output:-ABCDEF234
        SFRTG456
            WER,TST890
            TYUI111
0
Hi all,

I am using the Rublar online regular expression editor (http://rubular.com/) to test my regular expression.

I am triying to build a regular expression to match a multi-line string between 2 patterns: #Reference and #Parents.
For example my test string is:
...
Test phrases:
#Reference
If, from devoted settings :
a) Verify if the detector
b) Power ON the detector telemetry
#Parents
Test new phrases ...

and my regular expresion I trying to do is:
^#Reference\n(.*\n.)
but it matches only:
#Reference
If, from devoted settings :
a

My regular expression it should finished by : #Parents
somthing like: ^#Reference\n(.*\n.)#Parents

Thanks for your help.
0
I have a regular expression: "(John) (.+?) "
And String: "John writes about this, and John Doe writes about that, and John Wayne writes about everything."
So I get the following result:
John writes
John Doe
John Wayne

Now I have a another string from user which specifies what needs to be done with the matched strings so for e.g.
%1-%2-%3
%3.%2
[%2]-[%3]-[%1]

So which means I need to replace the %1, %2, %3 etc.. matches with the actual matched items i.e.:
%1-%2-%3   ==== John writes-John Doe-John Wayne
...

How can I do this in Java? The second string which we need to get the matched result into can be of any type but will have the number %1,%2,%3... which we need to replace with the reg ex matches.

I have below code till now:
String covertTo="%1-%2-%3";
        String text    =
                  "John writes about this, and John Doe writes about that," +
                          " and John Wayne writes about everything."
                ;

        String patternString1 = "(John) (.+?) ";

        Pattern pattern = Pattern.compile(patternString1);
        Matcher matcher = pattern.matcher(text);

        while (matcher.find()) {      
            System.out.print("Start index: " + matcher.start());
            System.out.print(" End index: " + matcher.end() + " ");
            System.out.println("group: "+matcher.group());
          }

        //Need to write code to store the above matches into array and replace as required and output to …
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.