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

0
HTML5 and CSS3 Fundamentals
LVL 13
HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

I have over 400 products that have some extra html code that needs to be removed.  I am wanting some help with a Maria db sql statement that will replace the content with a space or nothing at all.  The string that needs to be removed is as follows:

Indole - <p><span class="heading">Product Label</span> - <span style="color: #909;"><br />Place your mouse cursor over the image to zoom in to read the label.<br /></span></p> <p><br /><img src="/Resources/labels/1506.jpg" alt="Product Label" /></p>

Open in new window


The image # needs to be a variable.

I tried this code but it isn't working with a specific image # and without:

SELECT REPLACE('<p><span class="heading">Product Label</span> - <span style="color: #909;"><br />Place your mouse cursor over the image to zoom in to read the label.<br /></span></p> <p><br /><img src="/Resources/labels/1839.jpg" alt="Product Label" /></p>', '<p><span class="heading">Product Label</span> - <span style="color: #909;"><br />Place your mouse cursor over the image to zoom in to read the label.<br /></span></p> <p><br /><img src="/Resources/labels/1839.jpg" alt="Product Label" /></p>'," ")
FROM wp_posts2;

Open in new window


SELECT REPLACE('<p><span class="heading">Product Label</span> - <span style="color: #909;"><br />Place your mouse cursor over the image to zoom in to read the label.<br /></span></p> <p><br /><img src="/Resources/labels/1839.jpg" alt="Product Label" /></p>', '<p><span class="heading">Product Label</span> - <span style="color: #909;"><br />Place your mouse cursor over the image to zoom in to read the label.<br /></span></p> <p><br /><img src="/Resources/labels/%.jpg" alt="Product Label" /></p>'," ")
FROM wp_posts2;

Open in new window


Please tell me the best way to replace these strings using an sql statement.

Thanks,
0
I need some help parsing an HTML table with PHP.

The table below is from the ESPN College Football final Standings page at http://www.espn.com/college-football/rankings
I want to get the team NAMES into an array so that I can loop over them. It appears that they are in the nodes that look like this:
<a data-clubhouse-uid="s:20~l:23~t:228" href="/college-football/team/_/id/228/clemson-tigers">
    Clemson
</a>

Open in new window


Here is a partial table:
<table cellpadding="0" cellspacing="0" class="Table2__table-scroller Table2__right-aligned Table2__table">
    <colgroup span="7" class="Table2__colgroup">
        <col class="Table2__col">
        <col class="Table2__col">
        <col class="Table2__col">
        <col class="Table2__col">
        <col class="Table2__col">
        <col class="Table2__col">
        <col class="Table2__col">
    </colgroup>
    <thead class="Table2__thead">
        <tr class="Table2__header-row Table2__tr Table2__even">
            <th title="" class="Table2__th">RK</th>
            <th title="" class="tl Table2__th">
                <div class="tl">
                    <!-- -->Team<!-- --> 
                </div>
            </th>
            <th title="" class="Table2__th">
                <div>
                    <!-- -->REC<!-- --> 
                </div>
            </th>
            <th title="" class="Table2__th">
                <div>
                    <!-- -->PTS<!-- --> 
                </div>
            </th>
    

Open in new window

0
Hi all,

 How to compare string within an array? That string contains backslashes, colon and paranthesis.

sample program:

use strict;
use warnings;

sub perl_func {
    my ($z, $x) = @_;

    print "\n";
    print "z: $z\n\n";
   
    my @lx=@$x;
    foreach my $tx (@lx)
    {
       
        if ($z !~ m|$tx|)
        {
            print "$z !~ $tx\n";
        }
        else
        {
            print "$z == $tx\n";
            return 1;
        }
    }
   
    print "\n";
    return 0;
   

}

#my @x = ("One", "Two", "Three", "Four", "Five");
#my $z = "Four";
#works fine for above x & z

my @x = ("One\\OnesPosition:Num (NumPerl)", "Two\\TensPosition:Num (NumPerl)", "Three\\HundresPosition:Num (NumPerl)", "Four\\ThosandsPosition:Num (NumPerl)", "Five\\TenThousPosition:Num (NumPerl)");
my $z = "Four\\ThosandsPosition:Num (NumPerl)";


if(perl_func($z, \@x))
{
    print "\nfound element\n";
}
else
{
    print "\nnot found element\n";
}
0
Hi Experts,

I am using SSRS and I want to create a subtotal on based on the first 7 character of the AccountID field.

So the example attached, I would have a subtotal for the account 101-002-xx,  101-007-xx and 102-002-xx.

Screenshot_1.png
0
Hi,
I'm fairly new to php and mysql but I'm creating a PHP and MySQL web application for a client. I have a register.php page with the following form fields:
Contact Name, Phone, Email, Password, Confirm Password, Ticket Holder Password and Ticket Holder Confirm Password, where Users can register/sign up to use the app. Once they do register, they get redirected to admin_login.php page where they can login and get full access to the app and various other pages I've created.

My Problem:
My Password validation functions aren't working and I'm not sure why. I want the passwords to be a minimum of 8 characters, contain one upper and lowercase letter, a number and a special character. I'm using a regular expressions code that I found online. What I want is to validate the Password fields, so if the User enters a password that meets the criteria mentioned above than it should INSERT the data INTO the database, if it doesn't meet the Password criteria mentioned above I want to display an error message saying: "Password must be minimum of 8 characters, contain one upper and lowercase letter, a  number and a special character". I'm new to using php functions and how to call them properly.

This is the code in my functions.php page:

<?php

// FUNCTIONS.php

// clean the form data to prevent injections

/* Built in functions used:
   trim()
   stripcslashes()
   htmlspecialchars()
   strip_tags()
   str_replace()
*/

function validateFormData($formData) {

Open in new window

0
I have a long text that has this string$

.... value="variablechars" .....

or
.... value='varchars'....

I need to implement a regular expression in asp to extract these strings and create a list (each record with 2 items)

Once extracted I have no problem in creating the list in my database

the list

name1, value="str1"
name2, value="str2"
name3,value="str3"

name4,value='str4'
name5,value='str5'
name6,value='str5'

I extract email with this code (asp)

Set RegularExpressionObject = Server.CreateObject("VBScript.RegExp")
With RegularExpressionObject
 .Pattern = "[_a-zA-Z\d\-\.]+@[_a-zA-Z\d\-]+(\.[_a-zA-Z\d\-]+)+"
 .IgnoreCase = True
 .Global = True
 End With

 StringToSearch = blocks(x)
 set objMatches = RegularExpressionObject.Execute(StringToSearch)
 for each objMatch in objMatches
 email=objMatch.value
 next

Also extract  strings as

&nbsp;Actividad <br/>

I guess I am missing the Pattern

Example

<img src="image.png" />&nbsp;Actividad <br/><input type="text" readonly class="textboxif" style="width: 410px;" value="Name of activity" name="sector" id="sector"/></td><td>

Here the items would be

Actividad,Name of activity

I have many atrings that I have to extract the data from

Any ideas?
0
I need a Regex which can convert this character   to ' in PHP.
Looking forward for help.

Thanks
0
Im trying to write a jQuery validation method, but having issues getting the RegEx to match up.

Im trying to match a 16 character string, which has to be uppercase.
First 5 characters need to be A-Z
Next 6 characters are numeric
Next 2 charachers are A-Z
Last 3 characters can be A-Z or 0-9

So I got the following regex statment:-
5[A-Z]6[0-9]2[A-Z]3[[A-Z]|[0-9]

However when I run it thought an online checker it says it has matched 8, where surely it should say its matched 1, I can then put into my jQuery to say if the match == 1 then its good else there is a problem.

Any ideas what Im doing wrong, or am I miss understanding something here?
0
I am using CMS to build HTML pages. All the html content is saved in Database. That HTML code contains text, formatted html and images etc.
Each image has <img> tag.

I am using Sphinx Full Text Search. I have make an index of the column which contains HTML of the page.

Here is my code


include 'C:\Sphinx\api\sphinxapi.php';

// Build search query
$cl = new SphinxClient();

$cl->SetServer( "localhost", 9312 );
$cl->SetMatchMode( SPH_MATCH_EXTENDED  );
$cl->SetRankingMode ( SPH_RANK_SPH04 );

$q  = '"' . $cl->EscapeString($_REQUEST['input']) . '"/1';
$searchresults = $cl->Query($q, 'my_index' );

if (!isset($searchresults["matches"]) )
{
	print("No Result Found");
	exit();
}


foreach($searchresults["matches"] as $match)
{

  $entry = array("title" => "");
  if(isset($match["attrs"]))
  {
        "<br>".$entry["title"] = (isset($match["attrs"]["title"]) ? $match["attrs"]["title"] : "");	
	$entity["entity_id"]  = (isset($match["attrs"]["entity_id"]) ? $match["attrs"]["entity_id"] : "");
	
						// Getting Link //
	$qry = "select * from url_alias where source like 'node/$entity[entity_id]'";
	$rst = mysqli_query($conn,$qry) or die(mysqli_error());
	$rst_fieds = mysqli_fetch_array($rst);
	$url_alias_link = $rst_fieds['alias'];
	   
	$entry["bundle"] = (isset($match["attrs"]["field_body_value"]) ? $match["attrs"]["field_body_value"] : "")."<br>";
	$entry["bundle2"] = strip_tags(html_entity_decode($entry["bundle"]));
	
		print "<div class='search-web'><a 

Open in new window

0
PMI ACP® Project Management
LVL 13
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

Dear expert

I would like to programming using powershell the idea is in a test like this:

Text, text, Text, text, Text, text,
Text, text, Text, text, Text, text, Text,
text, Text, text, Text, text, Text, text, Text,
 
text1, Text2, text3, Text4, text5, Text6, text, Text, text, Text, text, Text, text, Text,

I was to grab the last line of text like  text5 and replace the text5 to test_weti is it possible?
1
Help me to fetch first 3 lines of my email body by regular expression
0
Using Oracl regular expressions I want to extract character after the \

'OPS$BCTGTWDOM\SMANAVI'     Output => SMANAVI

How can I do this?

Thanks
0
Is there any machine learning algorithm using which we can detect/identify the articles from multiple news pages of any website.I tried it using Beautifulsoup/python fetching all links and processing it based on regular expressions but its taking much time.

Any help or suggestion will be much appreciated.
0
Hi there,
Is there a way/tool/ search engine that would allow me to search for multiple variations of the same phrase at the same time?
For example, I want to search for "revealing his true belief". But I also want to search for all the phrases that have the same or similar meaning like"betraying their real opinion".
The total number of words here is 8 but there are many different ways to combine the words so there are many different potential alternative phrases: "revealing his true opinion" "revealing his real opinion" "betraying our real opinion" etc….
Is there a way to accomplish this in two conditions?
1- I determine the alternatives. So I specify that for "word 1 word 2 word 3 word4", the alternatives for word 1 are: Only revealing or showing.
2- Use all the possible synonyms or even antonyms for "revealing" in word 1.
The tips I got so far from Reddit
"
Word2Vec or Doc2Vec is something that can be used for this, depending on whether you just wish to substitute synonyms or match the distributional semantics of arbitrary phrases.

---
If you don’t know your alternatives (e.g., you don’t know that revealing is similar to showing), then you need something than can do synonyms. Most search engines (e.g., Google) can do this, as can some natural language processing programs.

If you do know the alternatives, you can describe your pattern to a search engine or most computer programs using regular expressions. A regex that would match your example would be …
0
How would i get all child elements of a root element by class name using a regex pattern?

something like this

var items = $("#root_element_id").children("div:regex(class,\_[a-z0-9]{4})");
0
I have pattern "\A\bAbril\b[19]|([2]\d)\d{2}\z". The C# call I'm making is Regex.IsMatch(sInputPwd, @sPattern, RegexOptions.IgnoreCase). I only want it to match with passwords starting with AbrilYYYY (where YYYY is a 4 digit year) and with nothing appended but it's also matching passwords such as oneAbril2017, Abril2016two and even Ab2017 comes back as a match.
0
HttpWebResponse response = null;

                try { response = request.GetResponse() as HttpWebResponse; }

                catch (WebException) { return null; }



                // Regular expression for an HTML title

                string regex = @"(?<=<title.*>)([\s\S]*)(?=</title>)";

Open in new window


i want to understand what this do?
0
How to validate if a string has  a pattern  
(01)xxxxxxx(17)yyyyy(10) zzzzz(21)aaaaaa (30)bbb
where
xxxxx is a numeric digits with a fixed  length of 14 digits.
yyyyy is a numeric digits with a fixed length of 6 digits
zzzzz  is alphanumeric value with a variable length between 7-20 character (should allow special characters like  - , / . \)
aaaa  is alphanumeric value with a variable length between 8-20 character without any special characters
bbb is numeric digit with a fixed variable length upto 5 digiits.


I am using ASP.net vb program and want to use RegEx functions to validate a input string.

Can you share the validation criteria i need to use.

Thank you
0
Introduction to Web Design
LVL 13
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

Can someone please help to create regular pattern in c using regex.h to match sub string without matching terminating . character.

For example, from below string pattern should match “hello world.” and “hello world” (there is no . char at the end of second match)

|hello world.|hello world.

Thanks for your input!
0
I need help to build regular expression pattern in c using regex.h. I have a string having pipe separated fields.

foo|this is first field.|this is second field.|this is third filed.

I have to create pattern at run time to  match complete field by sub string of it.  for example "second" will match  "this is second field." and "first" will match "this is first field." but "third" should match "this is third filed"  without including terminating . character.

If there are more then one . at the end then it should match them except last . character for example if third filed is "|this is third field..." then it should match "this is third field.."

can some one please help to create this pattern.
0
Hello,
I'm facing a great wall when dealing with regex expression which is supposed to filter email addresses with some exclusions of formatting of those email addresses

I need to apply a kind of standard regex expression
\b[!#\$%&amp;'\*\+\-\/=\?\^_`{\|}~a-zA-Z0-9][!#\$%&amp;'\*\+\-\/=\?\^_`{\|}~a-zA-Z0-9\.]*[!#\$%&amp;'\*\+\-\/=\?\^_`{\|}~a-zA-Z0-9]@[a-zA-Z0-9\-][a-zA-Z0-9\-\.]+[a-zA-Z0-9\-]\b

Open in new window

which would do:
### Include ###
anyvalidaddress@anyvalid.domain

### Exclude ###
<anyvalidaddress@anyvalid.domain
<anyvalidaddress@anyvalid.domain>
<mailto:anyvalidaddress@anyvalid.domain>

On purpose i didn't mention real email addresses, basically because regex should filter ANY valid email address in some way: include or exclude.

Updated 7:23:PM MSK 2/6/18
below is the text which as example needs to be processed
The phrase regular expressions <anyvalidaddress@anyvalid.domain (and consequently, regexes) is often used to mean the specific, <anyvalidaddress@anyvalid.domain> standard textual syntax (distinct from the mathematical $A12345@example.com notation described below) for representing patterns that matching text <mailto:anyvalidaddress@anyvalid.domain> need to conform Abc\@def@example.com to. Each character in a regular expression (that is, each character in the string describing its pattern) is understood to be a metacharacter (with its special meaning), or a regular character (with its literal meaning). For example,
in anyvalid.address@anyu.any.anyvalid.domain the regex a. a <anyvalid.address@anyu.any.anyvalid.domain is a literal character which matches just 'a' and . is a meta character which matches
0
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
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

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.