Template:Regex/doc
This is a documentation subpage for Template:Regex. It contains usage information, categories and other content that is not part of the original template page. |
This template uses Lua: |
This template helps field the details in the wikitext of any page on the wiki. Normally searches ignore non-alphanumeric characters, but regular expressions (regex) accept all characters, plus metacharacters.
This template acts as a doorway by helping to develop a database query before running it on the wiki, and it does this by way of a search link that can also be used to share such discoveries. This template can also be used to learn the regular expression syntax of this version of Cirrus Search. You could use a bare {{search link}} to do all this, but this template saves a lot of typing (see below), so you only need to focus on entering a regexp.
An important alternative to using this template is performing a search directly with insource:"quotes-delimited arguments". These find wikitext without resorting to the regex searches this template does with insource:/slash-delimited arguments/, (which is a common syntax for regex searches). See § About CirrusSearch below for a better understanding of when this template is not needed. See below for other search tools.
Regular expressions are little computer programs, so it is characteristic of regex searches that they must always be tested to achieve their potential precision and thoroughness. But only a few of these intensive searches are technically able to run at a time against the database. This template minimizes your footprint, and guarantees that you will never run an untested regexp on every namespace in the wiki, even if your default search would let you do that. Use of this template enables the smallest possible footprint by using filters to limit the search domain. The first domain it targets is its own page in an ad hoc sandbox. Once your regexp pattern is honed, you add a search domain, by setting |prefix=
.
Parameters
|pattern= or {{{1}}} |
a regexp search pattern. Pattern is also the first positional parameter. |
|prefix= or {{{2}}} |
search domain. Prefix accepts a namespace number, or n for the current namespace, or : for mainspace, plus it has the usual prefix: meaning. Defaults to its current page (fullpagename) if a pattern is given alone.
|
|label= or {{{3}}} |
search link label. Label is also a positional parameter. |
Procedure
Decide whether you really need a thoroughly precise regexp search, or whether you can find the general wikitext of interest with a plain insource: filter. Examples of the plain insource: search are in § Parameters hastemplate and insource. In those cases, {{search link}} is sufficient, and sandboxing is not being suggested.
Namespace plus pagename equals fullpagename.
The procedure here is an iterative, read-evaluate-modify cycle.
- Find an existing fullpagename with the wikitext instances you are interested in targeting. Or create one yourself, and save it to the database so the query will find it.
- Open the wikitext, and enter a
|pattern=
. Prefix will be added later. - Show Preview. See the pattern in the newly created search link.
- Click on the search link. Note the bold text in each match, the centered, complete query, and note the count off to the right.
- Go back in your browser. Modify the regexp. Cycle. Or don't go back, you may need to majorly reset at the complete query.
- Enter a
|prefix=
. Start with a namespace. At the complete query trim results via the first letter(s) of pagenames tacked onto the namespace's automatically-given colon.
Step 6 is the core provision of this template. Caveat emptor: if you change the target, you'll have to re-save it to the database. If you target it again immediately, you'll want to purge that target. You don't have to ever purge if you just change |pattern=
. Note that you can target any single page using prefix:.
Help:Searching/Regex/Sandboxing
Help:Searching/Features{{#section:Help:Searching/Regex|Regular expressions}}{{#section:Help:Searching/Regex|Metacharacters}}
For this template, it is necessary to enter the pipe character using \{{!}} to find a literal pipe character in the wikitext.
{{#section:Help:Searching/Regex|Character classes}}{{#section:Help:Searching/Regex|Alternation}}
For this template, we need to replace the pipe character with {{!}} so that the "pipe" for the regexp won't confuse this template (or any other template). We need the parentheses at times because an alternation finds the longest pattern, and so the parentheses define that boundary, but it's a boundary you don't have to make if an alternation is the entire regexp patter.
Regexp searches are restricted on the server, so this template reduces the regex search footprint by using the prefix: filter every time, restricting the search domain to a namespace at most. The prefix: parameter can further filter a namespace by specifying pagenames that start with a given letter(s).
Templates for searching Wikipedia
Templates for searching Wikipedia
Search links
A search link stores a query in a link that takes you to live search results for that stored search. They're found on user pages and talk pages. Use one to bring the full feature set of MediaWiki Search, or features of external search engines, to bear on users unfamiliar with their search parameters.
One type of search link is a wikilink with all the capabilities of Search (search box), and with standard wikilink syntax: [[Special:Search/query| label]]. So this search link will (1) navigate: [[Special:search/Wales]] → Special:search/Wales or (2) search: [[Special:search/~Wales | search/~Wales]] → search/~Wales if you prefix a ~ tilde character.
All other search links are made from a template that will build a URL instead of wikilink. A URL can for example can call off-site search engines to search Wikipedia.
- {{Search link}} offers all the capabilities of Searching (search box), plus extra (URL) parameters for combinations of namespaces, and where you can escape the 20-results-per page-limitation, shareable: {{search link | et al | ''label'' | ns4 | ns5 | limit = 123}} → label.
- {{Regex}} – develop an advanced regex search. {{regex | \<--.*--> | label = Articles with comments missing the ! bang character | prefix=0}} → Articles with comments missing the ! bang character
- {{Template usage}} – develop a template regex search, and pinpoint specific template-call details. {{Template usage | Convert | \{{!}}C\{{!}}F | 0 | Articles that convert Celsius to Fahrenheit}} → Articles that convert Celsius to Fahrenheit
- {{ShortSearch}} – create three search links: {{ShortSearch | system operations research}} → WP GWP G (search Wikipedia, "Google" Wikipedia, and Google search)
- {{wpsearch}} – create five search links: {{wpsearch|collaborative search}} → collaborative search – Wikipedia search | Google search | Bing search | DuckDuckGo search | Yahoo search
- {{Wikidata search link}} – creates a Wikidata search link for descriptions, entities, items, properties, etc. → https://www.wikidata.org/w/index.php?search=Universe&title=Special:Search&fulltext=1
Search boxes
- {{Search box}} – Simple search box with choice of button below or to the right
- {{Search prefixes}} – Multiple pages' subpages are searched at once.
- {{Archive banner}} – For searching archives. It is of banner-style, like many other archive templates.
- {{Search lists}} – For searching from lists of lists.
Search boxes are made by <inputbox></inputbox>
tags. See mw:Extension:InputBox.
Page title searches
- {{Canned search}} – Link to automated search results for a given term
- {{In title}} – Search for pages whose name contains given words
- {{Look from}} – Search for pages whose name begins with a given word
For searches with exact matches, exact in upper and lower cases, or in punctuation marks, see Help:Searching § grep.
Other Wikipedia editor help
- {{Linksearch}} – Searches for external links matching a URL
- {{dabsearch|term}} – External tool to find page titles containing a
(term)
in parentheses; useful for Wikipedia:disambiguation study - {{Help desk searches}} – Navbox with list of links to Google pages, specialized to search for example user pages, village pump, etc.; useful for Wikipedia:Help desk tasks
- {{Spamsearch}} – Searches user pages for common spams, e.g. "we service", "leading manufacturer", etc.
See also
- Help:Searching
- Category:Search templates
- MediaWiki:Extension:InputBox § General syntax - how to create your own search box using
<inputbox></inputbox>
- {{template usage}}
- {{search link}}
- {{for loop}}
- {{in source}}