[pmwiki-users] Alphabetize by Title Without Leading Articles or Special Characters
5ko at 5ko.fr
Sun Mar 20 17:00:42 CDT 2016
You can use a search pattern like this:
'/^ *"?(The|An?) +/i'
This assumes that the quote always comes before the rest of the title.
The question mark after the quote means that there can be zero or one
quote, like the question mark after the An means that there can be a
single "n" or none (both artcles A and An will be found).
In some languages (French) typographical rules may require to have a
space between the quote and the text, in that case you could have
'/^ *"? *(The|An?) +/i'
the asterisk after the space means that there can be zero or more
The plus after the last space means that there can be one or more spaces
after A, An, The.
In most cases, several regular expressions can be written to match the
exact same strings.
The pattern on the cookbook has a tiny optimization but is harder to
understand for a beginner. In most cases, several regular expressions
can be written to match the exact same strings, you can have fun. :-)
On 2016-03-20 21:21, Jake Wartenberg wrote:
> I suspect this is a pretty basic regex question. I have quotation
> marks at
> the beginning of some of my titles, so I modified the TitleNoArticle
> function from the CustomPagelistSortOrderFunctions Cookbook page:
> 'preg_replace("/^ *((?:The|An?) |\")/i", "", (@$page["title"] ?
> $page["title"] : $AsSpacedFunction($name)), 1)';
> This works great for discarding the leading quotation marks, but I run
> a problem when I have *both* a leading quotation mark and an article
> (the/a/an) at the beginning of my title, in which case the page gets
> alphabetized under the article. I would be really grateful to anyone
> could show me how to modify the function to account for this.
More information about the pmwiki-users