Opened 11 years ago
Closed 11 years ago
#32878 closed defect (bug) (fixed)
More readable regular expressions for Press This URL's
| Reported by: | dd32 | Owned by: | dd32 |
|---|---|---|---|
| Priority: | normal | Milestone: | 4.4 |
| Component: | Press This | Version: | 4.2 |
| Severity: | normal | Keywords: | has-patch |
| Cc: | Focuses: |
Description
The regular expressions in Press This are hard to read.
The attached patch does (probably among other things)
- Switches to using
!instead of/as the delimiter, so that/doesn't need escaping inline - Removes the escaping of
?and.within character maps[.?]as they don't need escaping there - Adds case-insensitive matching to most expressions, aside from
/wp-includes/ - Removes the usage of
{1}as a single-character match is implied - Not certain what
preg_match( '/\/ad[sx]{1}?\//', $src )was supposed to match (/ad/,/ads/, and/adx/? If so, it's not currently matching/ad/, which this patch changes)
The patch is untested so far, needs to be reviewed to check I didn't miss anything.
Attachments (1)
Change History (5)
Note:
See TracTickets
for help on using tickets.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
The patch looks good. We can also make pretty much all groups non-capturing as they are only used to check if matches exist.
We can probably combine
!/([^./]+[-_])?(spinner|loading|spacer|blank)s?([-_][^./]+)?\.[a-z0-9]{3,4}!iand!/(spinner|loading|spacer|blank|rss)\.(gif|jpg|png)!i, as they are pretty close (assuming\.[a-z0-9]{3,4}is to match image extensions).