Let me break this regex.
/
Start regex.
.*
Match zero or most - in principle, we are ready to match this regular expression anywhere on the line.
(?:\?p= |\?q= |&q= |\?s=)
In this case, ?: Means "do not write anything inside this group." See http://www.regular-expressions.info/refadv.html
\? literally mean ? , which is usually a symbol meaning "match 0 or 1 copies of the previous token", but we want to match the actual ?.
Other than that, it just looks for a lot of different options to choose from ( | means that the regular expression is valid if I match what is in front of me or after me.)
([a-zA-Z0-9 +]*)
Now we match zero or more of any of the following characters in any layout: a-ZA-Z0-9 + And since it is inside () without ?: We fix it.
(?:&toggle= |&ie=utf-8 |&FORM= |&aq= |&x= |&gwp)
We see another ?: , So this is another not exciting group. Other than that, it is simply filled with literal characters separated by | s, so he does not make any fantasy of logic.
/
End regex.
In general, this regular expression scans a string for any instance of the first group that is not capturing, captures everything inside it, and then searches for any instance of the second group that is not capturing, and closes everything that was between the two groups not related to capturing. (Think of it as a “sandwich,” we look for the header and footer and grab anything that interests us)
After performing the regular expression, we do the following:
returns matches? [1] .split ('+'): [];
which captures the captured group and splits it into + into an array of strings.