We help IT Professionals succeed at work.

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.

Hi there,  I am getting a Uncaught TypeError: Cannot read property 'open' of undefined error, on Line 14. This is a function, that will open a popup on page load.  Not sure hoe to rectify it?

jQuery(document).ready(function($) {
	// Parse the URL
	function getParameterByName(name) {
	    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
	    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
	        results = regex.exec(location.search);
	    return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
	}
	// Give the URL parameters variable names
	var access = getParameterByName('access');
 
	// if access does not = yes then display the popup
	if (access != 'yes') {
		$.magnificPopup.open({
		  items: {
		    src: 'https://go.buildertrend.com/l/464372/2020-03-20/7sshdx'
		  },
		  type: 'iframe', modal: true
		});
	}
});

Open in new window

0
Hello,

I have one ascii format text file with more than 5000 lines.

Now what i'm trying to do i have to find some specific pattern lines and process them like below;

This is one of my sample line:
   subvar.str (                     $_code                    ) = '"PAQ2_Z6_TT5000"' ! $_partname, Definition

Open in new window


What i'm looking for (this is my search pattern:

! $_partname, Definition

Open in new window


and when i found this row i'm trying to get value ('"PAQ2_Z6_TT5000"') which is between two single apostrophe (').

Now i'd like to change it with new value "P5_YT1000".

At the end i'd like to change that line like below:
   subvar.str (                     $_code                    ) = '"P5_YT1000"' ! $_partname, Definition

Open in new window



I really need expert advise how to get this with proper approach.

Any help would be great!
0
Hello,

I tried to modify one ascii file with my inputs but i have to modify some lines with specific structures like below;

Structure is like below:
subvar.str (                     #SEARCH_TERM#                ) = '#VALUE#' ! Some Text

- There is no rule for white spaces around search term there can be found or not.


This is the real example:

subvar.str (                     $_partname                ) = '"XX-2000-1050"' ! $_partname, Definition


I'd like to find "$_partname" and then change it's value "XX-2000-1050". If it's fully string i have to put queto sign on my string otherwise if it's double or integer i'll not put anything begin and end of my value.

I'll appreciate if you can help about this.
0
I'm thinking I need a lookaround expression for this but the exact syntax is escaping me. I need a Regular Expression that will match on the word "then" but only once and only if the word "else" doesn't come before it. I'm using it for syntax highlighting and I want to make sure it highlights correctly for one and only one case. For example:

if (condition) then "something" else "something else"

Open in new window

should be 100% valid but

if (condition) else "something else" then "something"

Open in new window

should definitely fail

Things should also fail if the word "then" appears more than once unless that word is enclosed in double quotes. That one is probably a bit tricky.
0
I would like to use regex to test if a string has all uppercase text
e.g RO_om_0012" or RooM
Thanks
0
Hello, all.

I have these two commands

Example insert

{Something here} {{Something else here}}

Open in new window


Dim Regex2 As Regex = New Regex("\{.*?\}")
Dim Regex4 As Regex = New Regex("\{{.*?\}}")

Open in new window


They do not produce any errors, however.
The single { }
Will insert into the database for the {{ }}
In the database, you will see
{Something here}

Open in new window

With the curly brackets around it.

How can I distinguish between the two commands, so that only the double curly's will insert into its column, and the single curly will only insert into its column?

Thanks
Wayne
0
i would like to extract the first Rem that has a space after from the string in regex
 "RemLETS BUILD THE': Rem Room"
in the example Room should be the extracted word
 "Rem LETS BUILD THE': Rem Room"
in the example the entire sentence from LETS BUILD THE': Rem Room"
ignore case false
0
I've got a data export file from a system that contains Unicode data, but part of the flow to upload this into the target requires removing these extended characters.  I have to pull the data through Excel and into another tool.  Excel seems to error on these (not sure why, but it currently is).

I'm looking for a way to convert all characters that are above the ASCII character set into a '*' character using either VIM or UltraEdit (2 tools I have available to me).  There are a range of these characters and I don't know what all they are so I need something that isn't just matching on an individual character but a range of character values.

Does anyone know a regex in VIM or a way to do something like this in UltraEdit?
0
I need to do a somewhat complex text substitution in VIM.

For some reason the output file I have from a report contains some space characters I need to remove.  I have a field that should start on a very specific column, but at times there are added spaces before it (usually 1 or 2).  I need to keep all the characters before those extra spaces, but remove them.  I cannot search on just spaces because there are plenty.  I just need to remove a space or two, keeping everything before and after.

For example I might several rows like the following:

asdfasfd           qwerqwer         asdfasdfa          asdfasdf
eascerdf           qwercsseas        serseresd          asdfasdf
wecasdf           asdf                    daease              se3dfsa

In this example you can see that the third field in the second row has an extra space I need to remove.  Once I've done that everything will be aligned again.  I need to keep all the characters before and after this unwanted space.  There is not a fixed number of spaces between fields 2 and 3.  I do know the exact position where field 3 should start though.

So, I'd like a regex that eats up a specific number of characters and then then checks if the next character is a white space.  When this happens I want to put back the characters read, but not the white space.  The rest of the line will take care of itself.  The third field starts in position 980.

I was thinking to use something like \(.\{980}\), but this only …
0
What would be the regex for combining ( the regex below) "qa" or "test" coming before ",cmo")

(qa\.cmo|test\.cmo)

so test.cmo and qa.cmo will be identified without making the two different regexs as in my example?
1
I am looking for a regex pattern to  return true for these two string
("SELECT * FROM CIM_DATAFILE WHERE NAME = '" & Replace(sValue, "\", "\\") & "'")
strC = "'" Then


and false for ' "wwwww_0" or anything else

in vba
0
Hello All;

I have been using the ID3v2 component, ID3TagLibrary, to read the metadata of MP3 files uploaded to my server for a few years now.
And I just found out it will not keep the text format. Example.
It will take this
Dvořák
And change it to
DvoYk

I need a component that will NOT mess up the formatting of the text.
Any and all ideas will be greatly welcomed.

Thank you.
Wayne
0
Given the code snippet bellow  I need to extract each Place Name & Coord string

There might be zero 1 or many however I can't be sure what the delimiter will be when there are multiple the two samples are either  a comer or semi colon
I do know
 Place Name (Coord string) are in this format

print "Hello World!\n";
my @examples=("Place Name (Coord string )","Place Name2 (Coord string 2);Place Name3 (Coord string 3);Place Name4 (Coord string 4)","Place Name5 (Coord string 5), Place Name5 (Coord string 5),Place Name6 (Coord string 6)","Not Wanted");

foreach my $example (@examples){
    if($example =~ m/(.*)\((.*)\)([,;])?/g){
        
        my $Place =$1;
        my $Coord = $2;
        
        # do stuff with each
        print "$Place  $Coord\n";
    }
    
}

Open in new window



I thought about splitting on the delimiter then pushing into an array which might work for multiple but seems to fail for single
0
I am new to regex and I am burning hours just to get it right. Maybe I can learn it later but I am in a rush. I need to allow these patterns

NPA-XXX-XXXX
(NPA) XXX-XXXX
NPAXXXXXXX

where NPA = numbers 0 to 9
   and X is also any number 0 to 9

so this is valid

123-456-7890
1234567890
(123) 456-7890

but not this

(123)-456-7890   // because there is a dash after closing parenthesis
(123)456-7890    // because there is no space after closing parenthesis
QWE-456-7890  // because there are one or more alpha characters


What would be the regular expression that would match the valid?
0
Hello
I have :
hotspot,info,debug hotspot: lm (192.168.1.5): logged out: idle timeout

lm is a user
I want to get all log records that contain: hotspot,info,debug hotspot: theusername  and display only the user
I tried with:
hotspot,info,debug hotspot:\s+[a-zA-Z]+
I get the result with hotspot,info,debug hotspot: so how I can search but not show the user only
thanks.
0
Hello,
I want to log all rysylog I configure and everything is fine.
I create a new template that is:
template(name="stdSQLformat" type="string" option.sql="on" string="insert into SystemEvents (Message, Message2, Facility, FromHost, Priority, DeviceReportedTime, ReceivedAt, InfoUnitID, SysLogTag) values ('%msg%','%msg:R,ERE,0,DFLT,1:([0-9]+\.){3}[0-9]+[:]?([0-9]+)?"--end%', %syslogfacility%, '%HOSTNAME%', %syslogpriority%, '%timereported:::date-mysql%', '%timegenerated:::date-mysql%', %iut%, '%syslogtag%')")
but when I run rsyslog I get:
error during parsing file /etc/rsyslog.d/mysql.conf, on or before line 8: invalid character '"' in object definit
I know that the problem is with
%msg:R,ERE,0,DFLT,1:([0-9]+\.){3}[0-9]+[:]?([0-9]+)?"--end%
but I don't understand what I have to do !
thanks.
0
I have a long list of towns/cities, here's a sample:

1      Tórshavn      STR      13,335
2      Klaksvík      NOR      4,842
3      Hoyvík      STR      4,124
4      Argir      STR      2,188
5      Fuglafjørður      EYS      1,541
6      Vágur      SUD      1,342
7      Vestmanna      STR      1,236
8      Miðvágur      VAG      1,120
9      Sørvágur      VAG      1,108
10      Saltangará      EYS      1,012

I wish to efficiently create a list of just the towns/cities in Notepad++ so it looks as follows;

Tórshavn
Klaksvík
Hoyvík
Argir
Fuglafjørður
Vágur
Vestmanna
Miðvágur
Sørvágur
Saltangará

In Notepad++ what regular expression can I use to do this in the Replace "Find it" box.

Thank you
regexp.jpg
0
Im trying to find out if a textbox for a password contains a special character, so written the following code:-
$("#txtPassword").on("keyup", function () {
	if ($("#txtPassword").val().match(/(.*[!,%,&,@,#,$,^,*,?,{,},|,(,),[,],_,-,/,\])/)) {
  	$("#tdContainsSymbol").html("P");
  } else {
  	$("#tdContainsSymbol").html("O");
  }
});

Open in new window


However its saying there is an issue with the regex command, Im assuming its to do with escape characters so changed the characters like []|\ and put a \ as an escape character, but didnt work.

Any ideas?
0
Hello,

I'd like to parse part1 and part2 name from my below string structure with Regex.Match.

I don't know it can be appliable but my string is like below;

$J_____dummy_part1_to_part2_sometext

if it's not matching i'd like return string.empty for part1 and part2

Any help would be great!.
Thanks.
0
I need help writing a RegEx query.

Say I have a bunch of lines like such:
<CDSECTION install="N" language="german" name="applstart" size="4172"></CDSECTION>
<CDSECTION install="N" language="german" name="applstart"></CDSECTION>
<CDSECTION install="N" language="german" name="applstart" size="374"></CDSECTION>
<CDSECTION install="N" language="german" name="applstart" size="9734137"></CDSECTION>
<CDSECTION install="N" language="german" name="applstart"></CDSECTION>

Open in new window

I want to identify only the lines that have like > size="4172" < in it.
The number in quotations could be anything, but as long as the line contains > size="{any number}" <.

So in the above example I'd need the following selected:
<CDSECTION install="N" language="german" name="applstart" size="4172"></CDSECTION>
<CDSECTION install="N" language="german" name="applstart"></CDSECTION>
<CDSECTION install="N" language="german" name="applstart" size="374"></CDSECTION>
<CDSECTION install="N" language="german" name="applstart" size="9734137"></CDSECTION>

<CDSECTION install="N" language="german" name="applstart"></CDSECTION>

Thanks.
0
What is the code in regex to ensure user enters a minimum of 6 digits and a maximum of 6 digits? I currently have

\d{6,6}

But I don't get the error message indicating that I have entered more than 6 digits.
0
In .Net the regex (?<=>[^<]*?)\bă works as expected (find words that start with ă and are not located within a tag).

But in JavaScript Chrome \b won't work with Unicode texts.

What would be the correct equivalent in JavaScript for the above .Net expression?

(I am referring to the latest versions of regex/regexp)
0
Given the code bellow

using System;
using System.Text;				
using System.Text.RegularExpressions;

public class Program
{
	public static void Main()
	{
		string Sentance  =@"pest, irritant, nag, nuisance, Colloq pain, pain in the neck or Brit taboo arse or US taboo ass; Slang US nudge";
		string[] Colloq = new string[] { "Brit", "US", "Australian", "Canadian", "New Zealand" };
        string[] Labels = new string[] { "Colloq", "Slang", "Taboo", "Archaic", "Old-fashioned" };
		
		string[] Words = Sentance.Split(',');
		foreach (var word in Words)
		{
			if (word.Contains(Labels))
			{
				// everything upto the next ; is that Label 
				// I need to capture the Label , Colloq and word treat 'or' as separate word
			}
			else{
			AlternateWords alternateWords = new AlternateWords()
			{
				AlertnateWord = word.Trim()
			};
			thesauri.alternateWords.Add(alternateWords);
			}
		}

    }
	
}

Open in new window


I need
AlertnateWord pest
AlertnateWord irritant
AlertnateWord  nag
AlertnateWord   nuisance

AlertnateWord Colloq pain
AlertnateWord Colloq pain in the neck
AlertnateWord Colloq Brit taboo arse
AlertnateWord Colloq US taboo ass
AlertnateWord Slang US nudge

Open in new window


Sorry I don't know how else to explain this
0
Hi all,
Im using the following regex:
/<a(.*?)>(.*?)<\/a>/m

Open in new window


How can I change this to find all links that have the word "advanced" (case insentitive) anywhere in the the link text or the URL?
0
Attached is a section from "BitBake User's Manual" that uses inline Python variable expansion to set variables.
Please explain in detail how the DATE variable is set.
python.PNG
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.

Top Experts In
Regular Expressions
<
Monthly
>