What is the difference between /<.>/ and /<[.]>/ in regular expressions [duplicate] - regex

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.

Related

Notepad++ replace dots/punctuations that are alone not beeing surrounded by numbers [duplicate]

This question already has answers here:
What special characters must be escaped in regular expressions?
(13 answers)
Closed 5 years ago.
I would like to find dots/punctuations not surrounded by any numerics or alphanumerics (in other words surrounded by nothing) and replace these with nothing using Notepad++ and regex.
I tried using
(?<![a-zA-Z0-9]).(?![a-zA-Z0-9])
but it replaces all the numbers surrounding each dot with nothing.
How can this expression be adjusted appropiately for use in Notepad++ ?
You need to escape the . character:
(?<![a-zA-Z0-9])\.(?![a-zA-Z0-9])

RegEx----What is mean "?!:"? [duplicate]

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'

What does "(?! ... )" do in a Perl regex? [duplicate]

This question already has answers here:
What does ?! mean?
(3 answers)
Closed 6 years ago.
$str = "doctor_who:eeh1234LMNOP51234.123";
I want to match doctor_who:ee not doctor_who:eeh;
$str =~ m/doctor_who:e(?!eh)[epx];
I want to know the role of regular expression within Parentheses;
A component like (?! ... ) will fail to match if the following characters in the target string match the enclosed regex pattern. It's called a negative look-ahead
It's unclear whether you need help to form a pattern to your requirements, or if you've come across a pattern that you don't understand
If I was writing it, I'd look at your specification
I want to match 'doctor_who:ee' not 'doctor_who:eeh'
You want to match doctor_who:ee that isn't followed by h, which is
/doctor_who:ee(?!h)/

Perl Regular expression look ahead [duplicate]

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

How To Negate Regex [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Regular expression to match string not containing a word?
How can I invert a regular expression in JavaScript?
Say I have the regex foo123. How do I match everything that is not foo123?
Use negative lookahead for this.
(?!foo123).+
matches any string except foo123
If you want to match empty string also, use (?!foo123).*
In your case (according to the comment) the required regex is (?!P[0-9]{1,}).+.
It matches P and 123, but not P123.