I assume you mean the pattern '(https?://[\w./?=]+)|.'
( - start a capture group (as this is the first, it will be numbered 1)
http - match the literal characters
s? - match the literal "s" character "0 or 1 times" (i.e. the '?' quantifier means the previous item is optional)
:// - more literal characters to be matched
[ - the start of a character set definition
\w - a short-cut way to specify the character set definition of all alphanumeric characters plus the "_" character
. - as this is defined inside a character set definition, this is a 'literal' period character
/?= - more literal characters that make up the character set
]+ - the ']' ends tyhe character set definition; the '+' is a quantifier that means "repeat the previous item 1 or more times, matching as many times as possible"
) - closes the capture group
| - the alternation operator
. - as this is used outside a character set definition, this is the short-cut operator to match any character (except the '\n' character unless the "singleline" option is set)
So much for the item by item breakdown - what does all of this *mean*.
Lets start with the alternation operator: this is a very low precedence operator in regex patterns and so its effect is very far reaching (and is often the source of problems until you get the hang of how it works). What it does is to take everything on the left of the operator and try to match that sub-pattern to the text. If it succeeds, then it will ignore whatever is on the right and carry on. If the left-hand part fails to match, then the right-hand sub-pattern will be attempted.
Therefore what we are trying to do here is to match your URL (the left-hand pattern) and if that doesn't work, then simply match any character. As you can see, this will always "succeed", but we can tell the difference because we have surrounded the URL part with parentheses - if the first part matches a URL then the matched text will be captured in match group #1; if the second part matches the match group #1 will contain a null string. As it turns out, this is exactly what we want for the replacement operation.
The way the replacement operation works is to delete ALL of the matched text and then construct a replacement string which is inserted back into the text. Therefore we will either start by deleting the URL or the matched single character. The replacement string is made up of the text captured in match group #1 and a newline character: if we matched the URL then we are going to put the URL characters (plus the newline) back into the text; if it was a single character then we will insert the null character plus the newline into the text.
This means that we will end up with a series of blank lines with the occasional line with a URL on it.
To remove the excess blank lines, you need to look at how the blank lines appear in the text. A line either starts after the beginning of the text or after a newline character. A line ends either with the end of the text or a newline character. Therefore a blank line will be seen as two consecutive newline characters.
To delete the blank lines you need a search pattern of '\n\n' and a null replacement string.
If the line contains a URL, then the newline characters will have text in between them and so will not be found by this pattern and so those lines will be left unaltered.
Of course life is never quite that easy. For a start, some editors
use "\r\n" as the line terminator so you will need to alter the pattern
accordingly. Also, you may end up with some blank lines (especially at the start and end of the text)
- you can either delete these by hand if there are only a few or you
can make another pass over the text with the replacement pattern.
Susan