Click here to Skip to main content
15,885,546 members
Everything / General Programming / Regular Expressions

Regular Expressions

regular-expression

Great Reads

by Christoph Buenger
Describes PHP application development with the free Scavix Web Development Framework (Scavix-WDF).
by honey the codewitch
Build a feature rich, non-backtracking regular expression engine and code generator in C#
by honey the codewitch
Embed fast streaming C# code to match text based on inputted regular expressions
by Daniel Vaughan
A Visual Studio regex to remove someone's overzealous use of regions in VS. Find and replace: (^.*\#region.*$)|(^.*\#endregion.*$) Remember to enable regular expressions in the Visual Studio find and replace dialog.

Latest Articles

by honey the codewitch
How to validate fields for things like data entry applications.
by honey the codewitch
Easily add lexers to your project with this simple drop in NuGet package and a few annotations
by honey the codewitch
In this article, we explore the inner workings of Visual FA
by honey the codewitch
Continuing in the Visual FA series, now we explore API fundamentals

All Articles

Sort by Updated

Regular Expressions 

N 24 Apr 2024 by honey the codewitch
How to validate fields for things like data entry applications.
4 Feb 2024 by honey the codewitch
Easily add lexers to your project with this simple drop in NuGet package and a few annotations
20 Jan 2024 by honey the codewitch
In this article, we explore the inner workings of Visual FA
18 Jan 2024 by honey the codewitch
Continuing in the Visual FA series, now we explore API fundamentals
15 Jan 2024 by honey the codewitch
In this article, we will use my Visual FA solution to explore finite automata concepts used for finding patterns in text.
6 Jan 2024 by honey the codewitch
Adventures in Reflection.Emit! Here I present a regular expression engine with a Compile() feature.
2 Jan 2024 by honey the codewitch
This article presents a program to help visualize regular expression mechanics.
20 Nov 2023 by honey the codewitch
Generate fast, easy to use lexers/scanners in major .NET languages
15 Nov 2023 by honey the codewitch
Generate tight C code to match text based on regular expressions
27 Jul 2023 by Maciej Los
Try this pattern: 245\-\d{2}\/\$\d{1}(.*?)\d{3}\-\d{2}\/\$\d{1} Example: regex101: build, test, and debug regex[^]
27 Jul 2023 by Member 16059392
Sorry, I know this has likely been asked before but I just can't get it to work in my use case. Need: In the below I need to extract the information between 245 and 250-03 (in bold). Quote: 100-01/$1 郑择魁; 245-02/$1 《阿Q正传》的思想和艺术 / 郑择魁;...
14 Jun 2023 by loyal ginger
I was trying to manipulate a string and needed to find various parts of a string. As an example, the following is the original string: C:\temp\tempa\target\Batch003\Images\20230127.120027\ROW\000014185386.jpg I wanted to find the part...
14 Jun 2023 by loyal ginger
I modified the regular expression in my question. The new one is (?(?:[a-zA-Z]:|\\)\\.+?)(?\\2023[0-1][0-9][0-3][0-9]\.[0-2][0-9][0-5][0-9][0-5][0-9]\\)(?[a-zA-Z]+)\\(?.+) It does...
13 Jun 2023 by OriginalGriff
If the Part to the right of the string you want is always ROW/filename.ext then I'd use that and Regex.Replace: (\\\d*\.\d*)(?=\\.+?\\..*\..{3}) Should do it.
9 May 2023 by Member 15849100
^ : start of string [A-Za-z\s]+ : match one or more occurrences of alphabets (both upper and lower case) and spaces $ : end of string This regular expression will only match strings that consist of alphabets and spaces, with no other characters...
24 Apr 2023 by Evilfish2000
I am reading the headers of an email message where the headers look like this: Date: 24 Apr 2023 09:43:44 +0200 Subject: HELP! Location 'Name249fc8e9-068b-47c3-a39c-a3e4cdfe2c16' is not responding! Content-Type: text/plain; charset=us-ascii...
24 Apr 2023 by Richard Deeming
As discussed in the comments, Microsoft officially recommend using MimeKit[^] for all email-related code. It's free and open-source, and it's actively maintained: GitHub - jstedfast/MimeKit: A .NET MIME creation and parser library with support...
24 Mar 2023 by jerome sergan
Hi all, i need help , I would like to know if what I am trying to do is possible, I am using php to run an API to retrieve company data for a CRM, this API accept regular expressions to do the search, for exemple if i'm literally using “CEO”, i...
24 Mar 2023 by GKP1992
That depends on what the API allows you to do. Whether it exposes a method that can accept a list of regexes or strings to include or exclude. Assuming the API to be a black-box. The only way you can know what it does is through the...
24 Mar 2023 by Chris Copeland
You can use regular expression negative look-aheads to ensure that certain patterns don't match within the string, while still having a matcher to find terms you are looking for. Here's an example regular expression[^] I can't guarantee that...
23 Mar 2023 by OriginalGriff
I'd use two regexes to make it more obvious and easier to maintain: the first to retrieve all matching strings, and then a second applied to the results which eliminates the "ignore list". While you could do it in a single regex - I think, I've...
11 Mar 2023 by LB2371
I've the following text ...bla bla bla 19 March 2023 bla bla bla... and the following regular expression to match months' names /January|February|March|April|May|June|July|August|September|October|November|December/g Is it possible to know...
11 Mar 2023 by PIEBALDconsult
This is C#, .net, and Linq, so I doubt you can use it, but maybe someone else can and maybe it will give you an idea. The groups will be named "1" through "12" (group "0" is the overall match) so we can test which group had a successful match...
5 Mar 2023 by Maciej Los
You mean, you want to achieve something like that: [ ]{2,} and replacement with \n? Result: Waiting to connect to bluetoothd... Agent registered [CHG] Controller 00:50:B6:80:4D:5D Pairable: yes [CHG] Controller 00:15:83:15:A2:CB Pairable: yes ...
22 Feb 2023 by ShifaMM
Need to match regex for below patterns I/p: 101-123 O/p: 101-123 What I have tried: private Regex Example = new Regex(@"^\d{3}-\d{3}(-[A-Z0-9]+)?(\([A-Z0-9]+\))?(\s[a-zA-Z0-9]+)*$");
21 Feb 2023 by CPallini
As a workaround you may search the result inside the regular expression pattern.
21 Feb 2023 by OriginalGriff
RegExp.prototype.exec() - JavaScript | MDN[^] returns an object with an index property.
21 Feb 2023 by OriginalGriff
Try:\d+-.+?[\s$] If you are going to use regular expressions, you need a helper tool. Get a copy of Expresso[^] - it's free, and it examines and generates Regular expressions.
21 Feb 2023 by Mike Hankey
A good site for experimenting with/Learning RegEx is regex101: build, test, and debug regex[^]
17 Feb 2023 by Versy Stems
I don't know how to perform a certain type of search and replace. What I have tried: To adapt an old source code within eclipse it will be very convenient to do a search and replace keeping one character of the original text and replacing it...
17 Feb 2023 by OriginalGriff
Try:([a-zA-Z]+)(?\d+)(...
14 Feb 2023 by Andre Oosthuizen
Assuming that your text of - Lorem ipsum span sit amet, consectetur adipiscing elit. Sed span velit, vestibulum vel pellentesque sed, mattis et span. Morbi justo est, pharetra vitae nisl at,
13 Feb 2023 by LB2371
I have the following HTML text: Lorem ipsum span sit amet, consectetur adipiscing elit. Sed span velit, vestibulum vel pellentesque sed, mattis et span. Morbi justo est, pharetra vitae...
13 Feb 2023 by LB2371
This is the solution I've found (but maybe there's a better one...): text.innerHTML = text.innerHTML.replace(/]+>/g, m => m.replace("span", "a"));
13 Feb 2023 by Chris Copeland
You could try: content.replaceAll(/]*)>/g, ''); This should cover most bases, though it's worth noting that dealing with HTML elements can be quite tricky. If somebody forgets to close an element then the matching might not...
1 Feb 2023 by Bikram Chhetri
I have a requirement like this:User can add the formula (suppose A + B) from the text box and it is saved as a formula in the database table and later he can calculate the other values as per this formula and get back the calculated value as a result with proper currency convert.If user...
31 Jan 2023 by LB2371
I need to match specific words in a text, but not if they're inside parentheses (with or without other words within). For example, in the text La première édition du code civil français est l'aboutissement d'une double réflexion menée afin...
31 Jan 2023 by OriginalGriff
The problem is that [^(] Means literally "Match anything that isn't an open perenthesis" - so it's not just spaces that are a problem - any character before "code" other than "(" will be matched. Personally, I wouldn't use a single Regex to do...
31 Jan 2023 by Chris Copeland
I was able to get a match using: (?![^(]*\))\s*(code (?:civil|pénal|de procédure civile|de procédure pénale))\s* To break this down: (?![^(]*\)) This is a negative lookahead, it stipulates that we shouldn't capture matches where the text...
11 Jan 2023 by Member 15881193
I want to extract only a number from the following: RTGS-VEERPAL/KARBH13267941306 TO STAMP PAPER CHARGES 2013 1348 By Clg/33790/ICICI/DELCTS1/166 RTGS-KUSUM TOMAR/CNRBH13271696922 RTGS-SHRI BALAJI BUILDHOME PVT /KARBH13294076078 By...
11 Jan 2023 by giocip
#STRING DATA MINING BY REGEX import re def main(): s = '''RTGS-VEERPAL/KARBH13267941306 TO STAMP PAPER CHARGES 2013 1348 By Clg/33790/ICICI/DELCTS1/166 RTGS-KUSUM TOMAR/CNRBH13271696922 RTGS-SHRI BALAJI BUILDHOME PVT /KARBH13294076078 By...
11 Jan 2023 by Zak River
Try running this example import re data = """ RTGS-VEERPAL/KARBH13267941306 TO STAMP PAPER CHARGES 2013 1348 By Clg/33790/ICICI/DELCTS1/166 RTGS-KUSUM TOMAR/CNRBH13271696922 RTGS-SHRI BALAJI BUILDHOME PVT /KARBH13294076078 By...
1 Jan 2023 by giocip
#STRING DATA MINING def main(): s = '''RTGS-VEERPAL/KARBH13267941306 TO STAMP PAPER CHARGES 2013 1348 By Clg/33790/ICICI/DELCTS1/166 RTGS-KUSUM TOMAR/CNRBH13271696922 RTGS-SHRI BALAJI BUILDHOME PVT /KARBH13294076078 By...
17 Dec 2022 by DoingWork
How to send special characters by SendKeys.SendWait() method ? I am sending this url "https://www.google.com/search?client=firefox-b-d&q=%3A}O" by SendKeys.SendWait(txt) method but error displays System.ArgumentException: 'SendKeys string...
17 Dec 2022 by Richard MacCutchan
You have a number of normal characters in your string surrounded by braces ({ and }). These are not valid special types. See SendKeys.Send(String) Method (System.Windows.Forms) | Microsoft Learn[^] for the full list.
16 Dec 2022 by Arifin Mustafa
>"123-456-7890".match(/(\d{3})...
16 Dec 2022 by Richard Deeming
It's not at all clear what you're trying to do, but your input clearly doesn't match the second pattern. Your first pattern matches any three digits, followed by a "-", followed by any other three digits. Your second patter matches any three...
14 Dec 2022 by Member 15864925
What I am trying to do is modify the regular expression of: [0-9]{3}( |-|)[0-9]{2}( |-|)[0-9]{4}(?![0-9]) to ignore strings that start with HSF. What I have tried: The best I can come up with is: ( |-|^|[^HSF])[0-9]{3}( |-|)[0-9]{2}(...
14 Dec 2022 by OriginalGriff
To add to what Richard has said, if you are going to use Regular Expressions, then get a copy of Expresso[^] - it's free, and it examines and generates Regular expressions.
14 Dec 2022 by Richard Deeming
Depending on the browsers you need to support, a negative lookbehind seems to work: (?
29 Oct 2022 by montaigne gremo
Hi, I want to delete all and ending +- symbols and whitespaces, how to do this? +Daviddance -disco +Alfredo Paixao +++++ -Serge Gamesbourg - The Cool, The Hip & The Square Dennis Taylor to Daviddance -disco ...
28 Oct 2022 by Richard MacCutchan
See the answer(s) to your previous question on this subject. And as suggested by OriginalGriff, you should get a copy of Expresso Regular Expression Tool[^] which will allow you to create REs quickly and easily.
27 Oct 2022 by montaigne gremo
Hi, I want to cleanup the lines which consist of only symbols + - spaces. How can I do this? FAUSTINE -fr +Reg Parham Armando Baez +Zimmer90 ++- +Deems -lofi + - Vittoria Siggillino Kyd Kango Nils Jitner - Nils -sjazz to FAUSTINE -fr...
27 Oct 2022 by Grant Mc
I have created a barcode validator, and some of the barcodes we get may be in a format such as (03) 15645 132156464 I would like to remove only spaces and brackets. I do not want to remove anything else, such as Barcode pending Although I can...
27 Oct 2022 by OriginalGriff
Your example as shown doesn;t work: it leaves ")" characters. And a simpler version would be: [\s()] which does it on a character-by-character basis. If you are going to use Regexes, then get a copy of Expresso[^] - it's free, and it examines,...
27 Oct 2022 by Grant Mc
Figured it out. sampleBarcode = Regex.Replace(sampleBarcode, @"\s+|\(+|\)+", "");
27 Oct 2022 by RickZeeland
You can practice with an online tool like RegExr[^] To match all spaces, + and - symbols try: ([ +-])+ To negate the result, try: ([^ +-])+ [Edit] To match lines, try: ([ +-]*\n)+
11 Oct 2022 by Maciej Los
Sorry, but your question is not clear... Seems you want to find a substring within a title... Regex is not for such of requirements. If you want to get a text within a "group-title=", try this: .group-title=\"(.*?)\" Example: regex101: build,...
10 Oct 2022 by Jake-J
Hi there, I'm new to regular expression and I'm trying to learn it. I have a string like this: #EXTINF:-1, tvg-name="THE NAME" tvg-logo="THE LOGO" group-title="THE TITLE",THE ITEM https://www.SampleSite.com I'm going to check if THE TITLE part...
9 Oct 2022 by Jake-J
Hi there, I have an M3U file and it's usually formatted likes this: #EXTM3U #EXTINF:-1, tvg-name="NAME 1" tvg-logo="LOGO" group-title="TITLE 1",ITEM 1 https://www.SampleSite1.com #EXTINF:-1, tvg-name="NAME 2" tvg-logo="LOGO"...
9 Oct 2022 by Dario Picca
I prefer use LINQ for this var objects = myString.Split(',') .Where(x => !string.IsNullOrEmpty(x)) .ToList();
9 Oct 2022 by OriginalGriff
A newline isn't an empty entry because any empty entry is an empty string: one which contains no characters at all. Newline is a character (or two characters on some systems) so it doesn't get removed. Try adding a newline to your separating...
5 Oct 2022 by Jake-J
Hi there, I want to use regex to parse a m3u list. Let's suppose we have this m3u item: #EXTINF:-1, tvg-name="THE NAME" tvg-logo="THE LOGO" group-title="THE TITLE",THE ITEM https://www.SampleSite.com I want to extract THE NAME,THE LOGO, THE...
5 Oct 2022 by Patrice T
Just a few interesting links to help building and debugging RegEx. Here is a link to RegEx documentation: perlre - perldoc.perl.org[^] Here is links to tools to help build RegEx and debug them: .NET Regex Tester - Regex Storm[^] Expresso Regular...
5 Oct 2022 by OriginalGriff
Try this: \btvg-name="([^"]+)".tvg-logo="([^"]+)".group-title="([^"]+)",(.*?)\n*(https?\S+) If you are going to work with regexes, get a copy of Expresso[^] - it's free, and it examines and generates Regular expressions.
23 Sep 2022 by theskiguy
I have been pounding my head trying to figure out a regex for the following scenario. I need the following to be matched: X11 X.25 X12. X-21.25 I don't want this matched: X I have come close with 2 options but both have issues. The 1st...
23 Sep 2022 by Patrice T
Quote: ([X]-?[0-9]*\.)[0-9]* As many parts are optionnal, you need a RegEx a little more complicated. [X]-?(\d+\.*[0-9]*|.[0-9]*) Just a few interesting links to help building and debugging RegEx. Here is a link to RegEx documentation: perlre...
23 Sep 2022 by OriginalGriff
Try this: ^X-?((\d+)|(\d+\.\d*)|(\.\d+))$ ^X-? Beginning of line or string X-, zero or one repetitions [1]: A numbered capture group. [(\d+)|(\d+\.\d*)|(\.\d+)] Select from 3 alternatives [2]: A numbered capture...
18 Sep 2022 by Apoorva 2022
From resume text, I want to extract the number of years of experience of a candidate. How I intended on obtaining this--> Years of experience is usually mentioned as '4 Years' or '6+ years' or '4.8 year'. What I have tried: ...
18 Sep 2022 by Patrice T
Instead of exp_p='[^\d]*(\d*\+? years|Years|year|Year)' Try exp_p='\d+(\.\d+)\s*(years|Years|year|Year)' Just a few interesting links to help building and debugging RegEx. Here is a link to RegEx documentation: perlre - perldoc.perl.org[^]...
15 Sep 2022 by Apoorva 2022
From resume text, I want to extract the number of years of experience of a candidate. How I intended on obtaining this--> Years of experience is usually mentioned as '4 years' or '6+ years'. How do I include '+' in the code while ensuring that...
15 Sep 2022 by OriginalGriff
Try: [^\d]*(\d*\+?) years|Years|year|Year
14 Sep 2022 by jsc42
1. VUGS is not getting printed correctly because you have assumed that the name of a company starts with a capital letter followed by zero or more lower case letters. However, VUGS starts with multiple capital letters. 2. You are assuming that...
14 Sep 2022 by Apoorva 2022
I'm writing a list of regular expressions to identify company names from text. This is what the text is like--> Summer Intern Genisup India Pvt. Ltd., Hosur, Tamil Nadu June 2021 – Aug 2021 1⁄2 Remote • Internship on the topic NLP: Topic...
12 Sep 2022 by Socks92
Hello, I'm trying to create a regex expression which creates validation for a target Url. Below are the rules I would like to include: - must begin with http:// or https:// - path name must be between 1-63 characters - no upper case characters...
12 Sep 2022 by OriginalGriff
That isn't even close. To select "http: or https:" you would need teh Regex "OR" operator '|' ^((http:)|(https:)).*$ Matches any string that starts with "http:" or "https:" But even with that, your rules are somewhat arbitrary: a valid URL can...
10 Sep 2022 by Apoorva 2022
I found the solution through the 'tika' library. Here's the code --> Extracting text from '.docx' file (Works for pdf as well) from tika import parser file = r'../content/drive/My Drive/foldy folder/resume.docx' file_data =...
8 Sep 2022 by Apoorva 2022
I want to extract an email id from a text 'file' using 'Regular Expressions'. Is there a way to feed a file as input, use the relevant regular expression, & get an email id from it? What I have tried: #Extracting email Ids...
8 Sep 2022 by OriginalGriff
To add to what Richard has said ... Email validation is pretty complicated, and your regex is far too simplistic - it allows illegal addresses such as "@." and doesn't find legal addresses such as "a.b@x.com", "a@x.co.uk", "a@x-y.com", and so...
8 Sep 2022 by Richard MacCutchan
You cannot use a filename for the scond parameter to the re — Regular expression operations — Python 3.10.7 documentation[^] findall function. You need to read the contents of the file and use the resulting text. See 7. Input and Output — Python...
21 Aug 2022 by Patrice T
Quote: I changed the regular expression to "(\\w+)\\s+" - no change. Then I tried "(\\w+)\\W" and it made things worse - now extracting ALL words. To extract all words, no matter the spaces, commas or points, I use this RegEx (\w+) Just a few...
20 Aug 2022 by Patrice T
Try this RegEx with groups 1, 2 and 4 ([0-9.]{10}).+- ([a-zA-Z]+( [a-zA-Z]+)*).+\d ([a-zA-Z]+( [a-zA-Z]+)*) Just a few interesting links to help building and debugging RegEx. Here is a link to RegEx documentation: perlre - perldoc.perl.org[^]...
20 Aug 2022 by Joe Doe234
Hi I have the following 2 type of string which I need to use the same regex for. string 1 : 2022.08.14 (19h45) - Salernitana 0-1 AS Roma (suppercoppa) string 2 : 2022.08.14 (19h45) - Salernitana 0-1 AS Roma I need to use one regex so I...
20 Aug 2022 by Brian C Hart
Example of how to use the caret (^) in Regexes that have specific matching requirements
20 Aug 2022 by OriginalGriff
When I run your regex (in Expresso) against either string I get similar results: String 1: 1: 2022.08.14 2: Salernitana 3: AS Roma (suppercoppa) String 2: 2022.08.14 2: Salernitana 3: AS Roma So ... what am I doing that you aren't? How did...
7 Aug 2022 by Himansh jain
I want to create regular expression for {SID} , {MetD}, {car} which should include curly brackets as well. What I have tried: Regex r = new Regex(@"^{[A-Za-z]}$"); the above regular expression is not working.
7 Aug 2022 by Patrice T
Quote: the above regular expression is not working. Try something like Regex r = new Regex(@"^{[A-Za-z]+}$"); Just a few interesting links to help building and debugging RegEx. Here is a link to RegEx documentation: perlre -...
7 Aug 2022 by OriginalGriff
Your regex specifies: ^ Start of line { A literal '{' [A-Za-z] Any single upper or lower case letter. } A literal '}' $ End of line You need to add a "multiple times" indicator to that:...
21 Jul 2022 by armanvaneld
hi i try to match id in this string in PCRE {"id":"zoo-coin","symbol":"zdcv2","name":"ZodiacsV2"} '"id":"(.*?)","symbol":"zdcv2"' What I have tried: i know the symbol,in this case ZodiacsV2,build a regexp for match id i use this code but not...
21 Jul 2022 by OriginalGriff
It works for me in Expresso: I get the whole string matched correctly, together with an anonymous group containing "zoo-coin" only. The way I'd do it is to switch to a non-capturing prefix and suffix: (?
18 Jul 2022 by SherinFemina
New to Selenium and working on few hands on activity. Below is my query: An application has been developed which enrolls the user details to the shipment company. Using the application user can track their shipment status and details. URL:...
18 Jul 2022 by Maciej Los
Not sure i understand you well, but... If you want to return boolean value, use find() method. See: java - regex isMatch returns false - Stack Overflow[^] Difference between matches() and find() in Java Regex - Stack Overflow[^] public static...
12 Jul 2022 by Soskipic
Select-String -Pattern "\b($($keywords -join '|'))\b"-AllMatches
12 Jul 2022 by Soskipic
I have a list of keywords (sometimes with non-alphanumeric characters) that I’d like to find in a list of files. I can do that with the code below, but I want to avoid matching keywords if they are found inside another word, e.g.: Keywords.csv:...
6 Jul 2022 by Dave Kreskowiak
\000 in a RegEx are ASCII values for characters in Octal (digits are 0 through 7) \x00 are ASCII values in hexadecimal For Unicode values, it's \u0000 Since you defined a range of values, you also included the values for Carriage Return and Line...
30 Jun 2022 by Member 11134333
I want the Regular Expression for Password Complexity The password must then contain characters of the following rules: 1- At least one Upper case letter 2- At least Lower case 3- At least one Numbers 4- Disallow the consecutive digits like...
30 Jun 2022 by OriginalGriff
Don't. It's a mess at best, and when the rules change - as they always do - the changes are a total PITA as the Regex is massively complex already - if you could implement each of your rules, which I don't think you can - "consecutive numbers"...
31 May 2022 by Member 15657898
Validators.pattern('[A-Z]{2}[ -][0-9]{1,2}(?: [A-Z])?(?: [A-Z]*)? [0-9]{4}')
24 May 2022 by CHOTIWAT CHOKDEEWATANA
i can't #include (regular Regular expressions)in my c program. I very new about programming, therefore i don,t know how to add file(or module i don't sure what's it called) in my c in my library. What I have tried: I try to download so...