This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 5 years ago.
codes image
If the question: Will the regular expression "?!:" What does that mean?
This is a "Negative Lookahead Assertion". This code is saying "this regular expression matches only if it begins with /wiki/ and is not followed by a colon".
Consider reading through https://www.regular-expressions.info and in particular the Lookahead and Lookbehind Zero-Length Assertions.
? --> zero or one occurrences of the previous expression
! --> negation
: --> simple colon
So... it would mean 'zero or one occurrences of the previous expression, not followed by a colon'
Related
This question already has answers here:
Regular expression to match a line that doesn't contain a word
(34 answers)
Closed 2 years ago.
I would like to come out with a regex expression that negate the matched results of regex expression: .google.*search. And, is it possible to achieve it with regex from the regex expression I am trying to negate?
Test data
[1] https://www.google.com/search?newwindow=1&sxsrf=ALeKk02MzEfbUp3jO4Np
[2] https://github.com/redis/redis-rb
[3] https://web.whatsapp.com/
Expected result
Row 2, 3 match the regex pattern and are part of the results.
the following regex does the trick
^(?!.+google.*search)
basically matching the beginning of the line then negating (?!) (negative lookahead) your regex.
You may use a negative lookahead here:
https?:\/\/(?!.*\.google\..*search).*
Demo
The "secret sauce" here is (?!.*\.google\..*search), which asserts that .google. followed by search does not occur anywhere within the URL to the right of the https:// portion.
This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 5 years ago.
Test String -
COAW983742892 COBW98374289
Regular Expression -
^(COBW|COaW|COXW)[0-9]+
Matching String is -
COAW983742892
My question is , why it don't match the both strings?
Your regex suggests that it should be the start of the String with ^ symbol at the start of regex.
Try this regex -
(COBW|COAW|COXW)[0-9]+
It will match both the strings.
You started your regex from ^ (the start of the string), so the only content
likely to be matched is the initial part of your source string.
Remove the starting ^ from the regex and it will match both substrings.
I assume that:
you use g option,
the true content of your regex is COAW (you changed A into a by mistake),
otherwise set i option.
This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 6 years ago.
I have tried to match <b> using regular expressions.
the pattern /<.>/ matches <b> but the pattern /<[.]>/ does not match.
What is the difference between /<.>/ and /<[.]>/ in regular expressions
When you put dot inside [] it is a literal dot, not a any character.
So the /<[.]>/ matches only <.>. It is the same as escaping a dot: \. in regexp.
This question already has answers here:
What do 'lazy' and 'greedy' mean in the context of regular expressions?
(13 answers)
Closed 6 years ago.
Choose which of the following strings match regular expression
(1 U 22)*2*
a. 22112222112211
b. 11112
c. The empty string.
d. 12121
e. 1121111222
I did a few search, U means " Ungreedy. Makes the quantifiers *+?{} consume only those characters absolutely necessary to form a match, leaving the remaining ones available for the next part of the pattern. When the "U" option is not in effect, an individual quantifier can be made non-greedy by following it with a question mark. Conversely, when "U" is in effect, the question mark makes an individual quantifier greedy. " https://www.cheatography.com/davechild/cheat-sheets/regular-expressions/
but I totally don't understand it, what does greedy regular expression and ungreedy regular expression mean? and can you show the example that I listed above?
Greedy means that it will try to find the longest matching string.
For the following string:
{ this} is a { test} }
Example of a Greedy regex
\{.*\}
This regex would match the whole following text:
{ this} is a { test} }
Non Greedy
\{.*\}
would match only
{ this}
This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 8 years ago.
What is the use of
?=
in perl regex
please tell the exact meaning and give some regex example.
(?=...)
is a positive lookahead, a type of zero-width assertion. What it's saying is that the match must be followed by whatever is within the parentheses but that part isn't captured.
Example:
.*(?=bar)
This pattern matches all the characters upto the string bar. When bar is detected then it stops matching. If a line contains more than one bar means it matches upto the last bar because .* does a greedy match.
DEMO