MLA docs → RegEx → Application Examples: Please explain string concatenation
-
Regular Expressions → Application Examples
/wp-admin/options-general.php?page=mla-settings-menu-documentation&mla_tab=documentation#mla_regular_expressions_examples
Please add the sentence in bold:
Here is a somewhat shorter alternative:
template[+name_only,extract('/(<filedate>\\d{4}.\\d{2}.\\d{2})/')+] ( [+matches:filedate,str_replace( '.', '-' )+] [+post_date,date( 'H:i:s' )+] )
That looks complicated, so let’s consider each part. The first part,
[+name_only,extract( ...
, extracts the three subparts of the date from the file name and stores them for later use. This part of the template returns an empty value, so it does not contribute to the new post_date value. The second part uses three[+matches: ...
data sources to build a valid date separated by dashes. The third part returns just the time portion of the original post_date. The second and third part are surrounded by parentheses, so an empty value is returned when the date values are not found in the file name. Furthermore between second and third part there is no literal text, so their output will be concatenated without any separating string between them. That will leave the original post_date value intact for any items whose file names lack a date portion.In the docs the code block is a single line. I dissected it into multiple lines in order to better understand/discuss it.
Assumption: Part 2 and 3, each in their own square brackets, get concatenated in place without any separator inbetween, because their closing and opening square brackets follow immediately with nothing inbetween. I know you explain the intermixing of return values and literals elsewhere in the documentation, but here a short reminder (like my bold text) would certainly help. Thanks!
- The topic ‘MLA docs → RegEx → Application Examples: Please explain string concatenation’ is closed to new replies.