[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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,

I want to know if there is a way that I can test the regex online that are created for Keyword Highlighting in SecureCRT. Below is the sample regex entries that I want to test and modify as per my requirement.

 "[*]For_Best_Results:_Set_Forground_Font_To_Gray_(Not_Black!)"
 "[*]Gray_Keywords_Are_To_Work_Around_Symbol_Delimited_Words"
 "[*]Special_Cases_That_Had_To_Be_ReOrderd"
 ".*'.*"
 "on-fail.*
 "[*]In_Enable_Mode"
 "^\w[^>]*#|hostname"
 "[*]NOT_In_Enable_mode"
 "^\w[^#]*>"
 "[*]Interfaces"
 "Embedded-Service-Engine\d\/\d"
 ".*thernet[0-9]+(?:[\/\.:][0-9]+)+[,:]?(?:\x20|$)"
 ".*thernet[0-9]+[,:]?(?:\x20|$)"
 "\b[efgt][a-z]*[0-9]+(?:[\/.:][0-9]+)+[,:*]?(?:\x20|$)"

Open in new window

1
Exploring SharePoint 2016
LVL 12
Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

I need a regular expression that will identify values that end with a plus sign.  I have a column that contains multiple weights in some cases and when it does I just need to extract the second value.  For example:

Values
607+800 lb    --> I need to identify the 607+ and remove.
822 + 44 lb    --> I need to identify the 822 + and remove.
555 lb
100 lb
0
I need a regular expression to check for a word in a string that has a "/".  

Value
---------
40005 Btu/h    ---->  I need to detect if the value has "Btu/h"
5009 BTU/H    ---->  I need to detect if the value has "BTU/H"
6999 BTU        -----> I also need to detect if value has just "BTU".
6700
900000 Btu
0
I need help with a regular expression that will check a column for a certain word, blanks and all white space.  I need a regx to check If the column below contains the word "NULL" or "Null" or  is blank or contains just white space.  

Description
----------------
NULL                  ------> If the column contains the word NULL.  
Plates
                             ----> White space example.  
Cups
Napkins and Cups
                           ------> Blank example
0
I need to delete a block of text that is on 400 pages of my mysql db.  It is in wp_posts and the post_content section.

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

Open in new window


This block is the same for all pages with the exception of the number specifying the .jpg

This is the sql I created but it isn't working even without the regex.

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

Open in new window


Please help me to create a query that will work for all numbered jpg's and just remove the block and replace it with nothing.

Thanks,
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
what is an .htaccess rule to have all pages direct to index.html or site root
0
Hello,
how I can  create a regular exp for :
c:\windows but without match the letter case.
thanks.
0
Exploring ASP.NET Core: Fundamentals
LVL 12
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

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
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
OWASP: Threats Fundamentals
LVL 12
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

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
I am working with some folk who are using Expression Engine Version 2. something.  They are considering upgrading to the latest version.  I know that version 2 and version 3 have a different directory setup.  Is there any definitive docs on how to upgrade with minimal pain? Tutorials? Plugins? How to videos?  I'm in the exploratory phase of this project and will appreciate any input on upgrading EE from 2.... to 3.0 - 4.0 and beyond!
0
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

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.