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.

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
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
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
i have a data to find and replace a values with other values in a column,ex "arjun + suresh + rajesh +marco" which has unique field to be replaced

ie: arjun should be replaced with 03 arjun, suresh should be replaced with 02 suresh, and rajesh with 08 rajesh, and marco with 06 marco.

after replacement the output will be "03 arjun +02 suresh +08 rajesh + 06 marco"

once we replace the values for the entire column in the same way mentioned above the each cell values should be sorted like ascending order with number "02 suresh+03 arjun +06 marco +08 rajesh"
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
Hi I need some help refining my regEx

I need to split the example the numbers eg ". 2 " however I also need  to split on "--n. 5 " and keep the "n."
Note: i'm first splitting on ". 1 " has the preceding Lexical doesn't have '--'

What I'm getting is every number, which I don't need!
I do need the Lexical If there is 1 And the sentance

using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;

public class Example
{
    public static void Main()
    {
        Regex SentanceSpit = new Regex(@"\.(\s+\d+\s+)|\.--([a-z]+\.)\s+\d+\s+");
        string Line = @"abandon v. 1 give up or over, yield, surrender, leave, cede, let go, deliver (up), turn over, relinquish: I can see no reason why we should abandon the house to thieves and vandals. 2 depart from, leave, desert, quit, go away from: The order was given to abandon ship. 3 desert, forsake, jilt, walk out on: He even abandoned his fianc,e. 4 give up, renounce; discontinue, forgo, drop, desist, abstain from: She abandoned cigarettes and whisky after the doctor's warning.--n. 5 recklessness, intemperance, wantonness, lack of restraint, unrestraint: He behaved with wild abandon after he received the inheritance.";
        // Output strings
		string Term;
		string Lexical; // not every example have diferant Lexical
        string[] WordsExample;
        string[] Words;
        string Example;
		string[] FirstSecond = Regex.Split(Line, @"\s1\s");
		if (FirstSecond.Length ==2)
		{
			string 

Open in new window

0
Using MS SQL Server and regex matching, how do you handle optional (zero or one instances) of a character?

models
-----------
H55N6800UK
H55NU8700UK
H60NEC5600UK

SELECT model FROM models WHERE (model LIKE 'H[0-9][0-9]N[0-9][0-9][0-9][0-9]UK') OR (model LIKE 'H[0-9][0-9]NU[0-9][0-9][0-9][0-9]UK') OR (model LIKE 'H[0-9][0-9]NEC[0-9][0-9][0-9][0-9]UK')

The SELECT statement above returns the 3 rows but uses an OR with three different regex expressions.  What I would like to do is use a single regex expression where the U or EC in the 5th character position are optionally matched.
Ideally a single regex expression to handle this would be something like:
 'H[0-9][0-9]N Optional U OR Optional EC   [0-9][0-9][0-9][0-9]UK'

The matching needs to be relatively tight and just using the % wildcard would accidentally match more items in the database than desired.

In practice, I will have one table of models to match (tens of thousands of records) and a second table of model-related data that includes the regex match in one column.  Then I'll simply join the tables in the form: SELECT * FROM MODELS LEFT OUTER JOIN MODELINFO ON MODELS.MODEL LIKE MODELINFO.REGEX.  There are already a huge number of permutations of the regex matches needed to cover my model data.  Inability to use an optional character in the regex will add a lot of work and double up a lot of rows.
0
I would like to prevent certain characters from being entered anything except &,(){}$%^!",

I thought this would work:
^(?=.*[A-Z])(?=.*[a-z])(?=.*[\d])(?=.*[\!\£\$\%\^\@\#\~])

Open in new window


Any help is appreciated.
0
I have a string that follows this pattern:  CT201945681-3012AMC  

I would like to have it keep all of the first Alpha Characters.  Then, it strips the first two digits of the year.  
It would remove the hyphen and any alpha characters after the hyphen.

So the example above would look like this:  CT19456813012    
The tricky part is the 20 from the year, so I would like to see that as a single Regex if possible.  

Thank You.
0
What is the proper JavaScript regex to cover these hosts?
  • apply.essexcredit.com
  • apply-uat.essexcredit.com
  • apply-qa.essexcredit.com

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.