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

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

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

I've got some HTML that looks like:

            <center>
                                                                        <table bgcolor="#E2DCC5" border="1" cellpadding="5" cellspacing="0" width="450">
                                                                              <tr>
                                                                                    <td>
                                                                                          <img align="left" alt="Tip" border="0" height="16" src="/global/images/icons/tip.gif" width="41">You might find it helpful to practice your presentation and get feedback on how well you did. The tool <img align="absbottom" alt="Tool" src="/global/Images/icons/tool.gif"><a href="/tools/improving_your_presentations.asp">Improving Your Presentations</a> provides some additional tips on making presentations and contains an observer feedback form to get targeted feedback on your presentation.
                                                                                    </td>
                                                                              </tr>
                                                                        </table>
                                                                  </center>

I'd like it to be changed to:
<div class="box-highlight box-content-round"><p><a class="float-left button-blue-dark button-round"><i class="fa fa-lightbulb-o fa-2x"></i> Tip</a>
You might find it helpful to practice your presentation and get feedback on how well you did. The tool <img align="absbottom" alt="Tool" src="/global/Images/icons/tool.gif"><a href="/tools/improving_your_presentations.asp">Improving Your Presentations</a> provides some additional tips on making presentations and contains an observer feedback form to get targeted feedback on your presentation.
</div>

Essentially it would look for the "tip.gif" and remove the table tags and add the <divs>

Is this doable?
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
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
I am using regular expressions with the "search & remove text" feature in Acrobat X Pro by editing the file SearchRedactPatterns.xml, as can be learned here: http://blogs.adobe.com/acrolaw/2011/05/creating_and_using_custom_redact/

I noticed, however, that my custom queries are always treated case-insensitive in Adobe, which they should not be. At least according to various online regex testers.

So, is there a way to force Acrobat to make the Regex case-sensitive?



 

Thanks in advance
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.

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
I have many redirect rules in my .htaccess and it is  slowing down the ttfb measurements.  I want to move them all to the vhost.conf file and place them in the respective virtual host code.

However, Prestashop automatically creates an .htaccess for the friendly urls option which I am using.

So how can I get the redirects in httpd.conf and still have Prestashop 1.5 work correctly?

I am on an Amazon VPS, Amazon Centos 6

Thanks,
0
I use windows 2008 server with IIS7 and have created the following URL rewrite rule:

<rule name="Rewrite english to /index.asp">
      <match url="english" />
      <action type="Rewrite" url="index.asp" />
 </rule>

Open in new window


What this does is when the URL is written as:

www.mywebsite.com/english

It would redirect to:

www.mywebsite.com/index.asp

The only problem is that if there are any files on the website which start with the text "english" then the rule would apply to that filename. I have an image called english-rose.jpg which would not display when this rule was in place. As soon as I removed the rule it was fine.

So what I want is to change the rule so it only matches on /english and no other variation.
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.