Questions tagged [regex]
Regular expressions provide a declarative language to match patterns within strings. They are commonly used for string validation, parsing, and transformation. Specify the language (PHP, Python, etc) or tool (grep, VS Code, Google Analytics, etc) that you are using. Do not post questions asking for an explanation of what a symbol means or what a particular regular expression will match.
23,415
questions
2275
votes
37
answers
3.8m
views
RegEx match open tags except XHTML self-contained tags
I need to match all of these opening tags:
<p>
<a href="foo">
But not self-closing tags:
<br />
<hr class="foo" />
I came up with this and wanted to make ...
52
votes
1
answer
212k
views
Reference - What does this regex mean?
What is this?
This is a collection of common Q&A. This is also a Community Wiki, so everyone is invited to participate in maintaining it.
Why is this?
regex is suffering from give me ze code type ...
4201
votes
78
answers
2.6m
views
How can I validate an email address using a regular expression?
Over the years I have slowly developed a regular expression that validates most email addresses correctly, assuming they don't use an IP address as the server part.
I use it in several PHP programs, ...
123
votes
4
answers
84k
views
My regex is matching too much. How do I make it stop? [duplicate]
I have this gigantic ugly string:
J0000000: Transaction A0001401 started on 8/22/2008 9:49:29 AM
J0000010: Project name: E:\foo.pf
J0000011: Job name: MBiek Direct Mail Test
J0000020: Document 1 - ...
166
votes
1
answer
156k
views
Learning Regular Expressions [closed]
I don't really understand regular expressions. Can you explain them to me in an easy-to-follow manner? If there are any online tools or books, could you also link to them?
5471
votes
79
answers
4.8m
views
How can I validate an email address in JavaScript?
I'd like to check if the user input is an email address in JavaScript, before sending it to a server or attempting to send an email to it, to prevent the most basic mistyping. How could I achieve this?...
5397
votes
34
answers
5.2m
views
Regular expression to match a line that doesn't contain a word
I know it's possible to match a word and then reverse the matches using other tools (e.g. grep -v). However, is it possible to match lines that do not contain a specific word, e.g. hede, using a ...
2462
votes
18
answers
1.2m
views
What is a non-capturing group in regular expressions?
How are non-capturing groups, i.e., (?:), used in regular expressions and what are they good for?
1058
votes
46
answers
1.2m
views
How to validate phone numbers using regex
I'm trying to put together a comprehensive regex to validate phone numbers. Ideally it would handle international formats, but it must handle US formats, including the following:
1-234-567-8901
1-234-...
756
votes
9
answers
1.3m
views
How to use Regular Expressions (Regex) in Microsoft Excel both in-cell and loops
How can I use regular expressions in Excel and take advantage of Excel's powerful grid-like setup for data manipulation?
In-cell function to return a matched pattern or replaced value in a string.
...
481
votes
14
answers
363k
views
What special characters must be escaped in regular expressions?
I am tired of always trying to guess, if I should escape special characters like '()[]{}|' etc. when using many implementations of regexps.
It is different with, for example, Python, sed, grep, awk, ...
241
votes
18
answers
82k
views
Using regular expressions to parse HTML: why not?
It seems like every question on stackoverflow where the asker is using regex to grab some information from HTML will inevitably have an "answer" that says not to use regex to parse HTML.
Why not? I'm ...
621
votes
19
answers
203k
views
Is there a RegExp.escape function in JavaScript?
I just want to create a regular expression out of any possible string.
var usersString = "Hello?!*`~World()[]";
var expression = new RegExp(RegExp.escape(usersString))
var matches = "...
1063
votes
65
answers
722k
views
What is the best regular expression to check if a string is a valid URL?
How can I check if a given string is a valid URL address?
My knowledge of regular expressions is basic and doesn't allow me to choose from the hundreds of regular expressions I've already seen on the ...
376
votes
7
answers
66k
views
Why does a RegExp with global flag give wrong results?
What is the problem with this regular expression when I use the global flag and the case insensitive flag? Query is a user generated input. The result should be [true, true].
var query = 'Foo B';
var ...