Regular expressions, sas [duplicate] - regex

This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 4 years ago.
I am looking at someone elses code and have a question. Below is the code. Where it says: ^DR DUE does that mean the string starts with DR DUE? I am new to perl regular expressions. Also, where ATM/(DEP|WTD) does this mean match ATM/(DEP|WTD) in the string? However, I thought that ( and ) were metacharacters too. Thanks for your help!
Removed

It will match a string containing
the string "COAL"
"DR DUE TO ATM/" placed at beginning of line and followed by "DEP" or "WTD".
So it will match:
COAL
(beginning of line)DR DUE TO ATM/DEP ERROR
(beginning of line)DR DUE TO ATM/WTD ERROR

Related

Regex.Matches problem in visual basic 2010 [duplicate]

This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 2 years ago.
I have this string
copiaElementos = "c'8 d'8 a8"
And when I do Regex.Matches(copiaElementos, "8.").Count() it returns 2
why is that? I don't understand, can anyone please give me a hand?
Thank you, best regards
That is because the . mathes one character. means you are matching an 8 followed by any charactrer, and there are exactly two of those (a space is considered a character too). Because the last one has no characters after it.
if you want to count the 8s in the string you should do Regex.Matches(copiaElementos, "8").Count(). Remember every character, even a space has its own meaning in regex.

Why use a negated empty set in a Regular Expression rather than .? [duplicate]

This question already has answers here:
How to use JavaScript regex over multiple lines?
(8 answers)
Reference - What does this regex mean?
(1 answer)
Closed 2 years ago.
I came across the following RE recently:
(?:<div class="something[^>]+?>[^]+<span class="somethingelse">([\d.])+|<div id="anotherthing[^"]+" class="[^"]*andanother)
The set [^] is valid in JavaScript but not in PCRE. My understanding of it is that it will match "anything not in the set". Since the set is empty, it must be matching anything (one or more times). So why would someone use [^]+ rather than simply .+ ? Is there some very subtle difference, perhaps to do with line endings?
. does not match line endings by default. You can enable the DOTALL option (e.g /.+/s) to make it match line endings as well.

How to match all strings that has only one dot using regular expression [duplicate]

This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 3 years ago.
I need to capture strings containing only one dot. String will mostly contains domain names like
test.com, fun.test.com, lesh.test.com.
I need to check only the first one and to ignore the string that has more than one dots.
How can I do this using regex?
Like this :
^[^.]+\.[^.]+$
Check explanations https://regex101.com/r/mn7Ccr/1

Capture anything between first [] not all the [] in string [duplicate]

This question already has answers here:
What is the meaning of the 'g' flag in regular expressions?
(10 answers)
Closed 4 years ago.
I have a string like [only this] i want [to] [capture].
I want to have only this. I have tried \[.*?\] regex but i have the following output:
"only this to capture"
And is it also possible to only capture anything between second [] like to in this case.
A bit unclear exactly what you're after, but the following regex captures the word to in your example.
\[.*?\].*?\[(.*?)\].*?\[.*?\]
Please see the following regexr for explanation.

Regex to Match Multiple Words In Different Order [duplicate]

This question already has answers here:
What is a word boundary in regex?
(13 answers)
Closed 4 years ago.
string sample: "universal studios japan"
How do i make so that it matches with "japan universal studios"
AND also with "japan univer"
Right now I'm using the following to regex :
^(?=.*\bjapan\b)(?=.*\buniversal\b)(?=.*\bstudios\b)
which works but
^(?=.*\bjapan\b)(?=.*\buniver\b)
does not work. It has to be a complete match for the second word..
^(?=.*\bjapan\b)(?=.*\buniversal\b) would work..
What changes do i need to make?
^(?=.*\bjapan\b)(?=.*\buniver(?:sal)?\b)
You can make sal optional.
See demo.
https://regex101.com/r/wDUC7j/1