This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 5 years ago.
I found these two expressions in documentation:
To match subdomains of mydomain.com: (^|.*\.)mydomain\.com
To match domain and subdomains of mydomain.com: (^|.*\.)*mydomain\.com
I can't understand why those expressions mean what they say they mean. Can anybody explain both expressions please?
Fist it is not a good regex expressions (it except other things that it should not) but i will explain the (^|.*\.)mydomain\.com (you will figure out the second)
between the parenthesis :
^ matches the starting position of the line
| acts like a Boolean OR ,between the expression before and the expression after the operator
.matches any character except line breaks
*Matches the preceding element zero or more times
\.matches a dot . character
For more information you could read wiki doc and use a great Regex tool
Related
This question already has answers here:
Regex Match all characters between two strings
(16 answers)
RegEx match open tags except XHTML self-contained tags
(35 answers)
Closed 2 years ago.
I would like to mark all strings between 2 strings with the regular expression.
Example:
https://regex101.com/r/Etfpol/1
I want regular expression to mark follow text:
Solution changed from
Resolved Time changed
Updated By changed from
enter image description here
Thanks
You can use positive lookbehind and positive lookahead to check the tags.
(?<=<Name>Description<\/Name><Value>).*?(?=<\/Value>)
Match results
Solution changed from
Resolved Time changed
Updated By changed from
If you prefer not to use them, this will work as well, but the full match will include the strings before and after your desired string.
(?:<Name>Description<\/Name><Value>)(.*?)(?:<\/Value>)
This question already has answers here:
Regex plus vs star difference? [duplicate]
(9 answers)
Closed 4 years ago.
Issue
I am having trouble matching lines with nothing but repeating equals signs (=) in Notepad++. I'm searching a plain text document for any line that begins with "=" and ends with "=". For instance, all these should match my regex:
========================
==================
==
=================================================
, etc.
My code
This is my regex:
^(=*)$
Not only does the regex not find equals signs, it falsely finds blank lines instead.
Rationale
^ = line begins with an equals sign.
=* = find any sequence of one or more equals signs
$= line ends with an equals sign
But my regex doesn't work. There must be some strange exception in Notepad++ because I verified that equals signs don't have to be escaped in JavaScript and my regex works fine at this online regex tester:
https://regex101.com/
Links I've found that haven't been fruitful
regex matching expression notepad++
Difficulties with adding spaces around equal signs using regular expressions with Notepad++
http://docs.notepad-plus-plus.org/index.php/Regular_Expressions
https://www.icewarp.com/support/online_help/203030104.htm
My questions
Why is my regex only returning blank lines?
If my regex is wrong, please explain why and what the correct regex is to do my find. Eventually I will do a replace as well, but I didn't want to cloud the issue.
Feedback on proposed duplicate
It was suggested that this post might be a duplicate of this question. This post is not a duplicate, and here is why:
Even if the content of the two posts were similar:
For a user to find the suggested post with "plus vs. star" in the title would suggest that he/she already had some idea what the problem was (i.e., use "plus" instead of "star").
Anyone else having this problem and being in my same predicament wouldn't necessarily know that plus vs star was the issue.
If the suggested post had come up as a possible answer when I searched "equals sign regex not working notepad++", I wouldn't have had to take my time to write this post.
* is zero or more.
+ is one or more.
Replace * with + in your regex.
So your regex would be ^(=+)$, this would match only lines with = and skip anything else.
This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 6 years ago.
I have a file where the application is configured to check the following Regex
[\x00-\x1F\x7F&&[^\x0A]&&[^\x0D]]
Can anyone please tell me the meaning of this regex expression exactly what it means. I do know that this regex expression ignored line feed and character feed. I even validated my file on http://regexr.com/ with the above specified regex expression and it shows no match found so not understanding why the regex is getting matched in the application.
FYI: I do not want the regex to match file as it is stopping my processing.
It could be that in Java and Ruby the regex expression && refers to character class intersection, while http://regexr.com/ doesn't support that expression and is trying to match literal & symbols. The regex you posted means match any characters from \x00 to \x1f or \x7f as long as it's not \x0A or \x0D.
This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 7 years ago.
Regex newbie here, so I was trying this website for fun: https://regex.alf.nu
In particular, I'm concerned about the "Ranges" section here: https://regex.alf.nu/2
I was able to get as far as ^[a-f]+, and couldn't figure out the rest. By accident, I added a $ to get ^[a-f]+$ which was actually the answer.
Trying to wrap my mind around the meaning of this regex. Can someone give the plain English explanation of what's happening here?
It seems to say "a string that starts and ends with one or more of the letters a through f," but that doesn't quite make sense for me, for instance, with the word "cajac" which seems to satisfy those conditions.
For those who can't see the URL, it's asking me to match these words:
abac
accede
adead
babe
bead
bebed
bedad
bedded
bedead
bedeaf
caba
caffa
dace
dade
daff
dead
deed
deface
faded
faff
feed
But NOT match these:
beam
buoy
canjac
chymia
corah
cupula
griece
hafter
idic
lucy
martyr
matron
messrs
mucose
relose
sonly
tegua
threap
towned
widish
yite
In English it means: Match any words which contain only the letters a thru f.
Your pattern, when broken down:
^ assert position at start of the string
[a-f]+ match a single character present in the list below:
+ Between one and unlimited times, as many times as possible, giving back as needed
a-f a single character in the range between a and f (case sensitive)
$ assert position at end of the string
You can also see a quick explanation of your patterns on the Regex101 webpage.
This question already has answers here:
RegEx match open tags except XHTML self-contained tags
(35 answers)
Closed 9 years ago.
I have this HTML code:
<td class="Class 1">Example</td><td class="Class2">Other Example</td>
and I am trying to use Regular Expressions in VB.NET to extract "Example" and "Other Example"
Dim parsedtext As MatchCollection = Regex.Matches(htmlcode, ">(.+)<)
(the htmlcode variable contains the html code mentioned above as a string.)
However, looking at
parsedtext(0).Groups(0)
, it is returning ">Example</td><td class="Class2">Other Example<". I do not understand why this is happening, and I have tried many other pattern strings and cannot figure this problem out. How would one extract all text between two specific characters such as > and < in the example above?
I agree with #ColeJohnson (no one on SO is allowed to believe otherwise, at this point), but it's a good example for teaching the concept of greedy versus non-greedy matching.
By default, regular expressions quantifiers (+, *, ?) "eat up" as much as possible, and only eat less when some part of the match fails. That's called greedy matching. To make it non-greedy, you use non-greedy quantifiers: +?, *?, ??.
That is,
">(.+?)<"
In other words, your .+ continued to match as many character as possible, before finding a <; so you see, your output was to be expected. If, however, hypothetically, it had not found that last <, it would have backtracked to the last time it "saw" a <.