regex


javascript - What's the meaning of /gi in a regex?

g modifier: global. All matches (don't return on first match) i modifier: insensitive. Case insensitive match (ignores case of [a-zA-Z]) In your case though i is immaterial as you dont capture [a-zA... Read More


python - Named regular expression group "(?P<group_name>regexp)": what does "P" stand for?

Since we're all guessing, I might as well give mine: I've always thought it stood for Python. That may sound pretty stupid -- what, P for Python?! -- but in my defense, I vaguely remembered this thre... Read More


java - Create array of regex matches

(4castle's answer is better than the below if you can assume Java >= 9) You need to create a matcher and use that to iteratively find matches. import java.util.regex.Matcher; import java.util.regex.... Read More


Is there a good, online, interactive regex tutorial?

Shameless plug: I wrote an interactive Regular Expression tutorial (RegexOne) over a couple weekends to help some friends learn regular expressions. They mentioned the real time examples seemed to he... Read More


regex - What is a regular expression for a MAC Address?

The standard (IEEE 802) format for printing MAC-48 addresses in human-friendly form is six groups of two hexadecimal digits, separated by hyphens - or colons :. So: ^([0-9A-Fa-f]{2}[:-]){5}([0-9A-F... Read More


What is the difference between square brackets and parentheses in a regex?

These regexes are equivalent (for matching purposes): /^(7|8|9)\d{9}$/ /^[789]\d{9}$/ /^[7-9]\d{9}$/ The explanation: (a|b|c) is a regex "OR" and means "a or b or c", although the presence of brac... Read More


Regex to extract URLs from href attribute in HTML with Python

import re url = '<p>Hello World</p><a href="http://example.com">More Examples</a><a href="http://example2.com">Even More Examples</a>' urls = re.findall('https?://(?:[-\w.]|(?:%[\da-fA-F]{2}))+', u... Read More


Type of compiled regex object in python

Python 3.5 introduced the typing module. Included therein is typing.Pattern, a _TypeAlias. Starting with Python 3.6, you can simply do: from typing import Pattern my_re = re.compile('foo') assert is... Read More


How to negate the whole regex?

Use negative lookaround: (?! pattern) Positive lookarounds can be used to assert that a pattern matches. Negative lookarounds is the opposite: it's used to assert that a pattern DOES NOT match. Some... Read More


regex - Regular expression to get a string between two strings in Javascript

A lookahead (that (?= part) does not consume any input. It is a zero-width assertion (as are boundary checks and lookbehinds). You want a regular match here, to consume the cow portion. To capture th... Read More