Convert regexp from JavaScript to PCRE format
Seen many questions on same topic here, but didn't find the answer :(
I've got this {{Infobox[^]*?({{[^{}]*?}}[^]*?)*}}
regex. Works as a charm in Javascript and here http://www.gskinner.com/RegExr/
In PHP it produces an error "Compilation failed: missing terminating ] for character class at offset 41".
I know about delimiters, also tried putting \ before { and } — didn't help.
{{For|the title track of the album|Master of Puppets (song)}}
{{Infobox Album <!-- See Wikipedia:WikiProject_Albums -->
| Name = Master of Puppets
| Type = Studio album
| Artist = [[Metallica]]
| Cover = Metallica - Master of Puppets.jpg
| Released = {{Start date|1986|3|3}}
| Recorded = September 1 – December 27, 1985 at [[Sweet Silence Studios]], [[Copenhagen]], [[Denmark]]
| Genre = [[Thrash metal]]
| Length = 54:41
| Label = [[Elektra Records|Elektra]], [[Music for Nations]], [[Vertigo Records|Vertigo]]
| Producer = Metallica, [[Flemming Rasmussen]]
| Last album = ''[[Ride the Lightning]]''<br/>(1984)
| This album = '''''Master of Puppets'''''<br/>(1986)
| Next album = ''[[...And Justice for All (album)|...And Justice for All]]''<br/>(1988)
| Misc = {{Singles
| Name = Master of Puppets
| Type = Studio
| single 1 = [[Master of Puppets (song)|Master of Puppets]]
| single 1 date = July 2, 1986
| single 2 = [[Battery (song)|Battery]]
| single 2 date = 1986
| single 3 = [[Welcome Home (Sanitarium)]]
| single 3 date = 1986
}}
}}
'''''Master of Puppets''''' is the third studio album by the American [[heavy metal music|heavy metal]] band [[Metallica]]. It was released on March 3, 1986 through [[Elektra Records]]. The album reached #29<ref>{{Cite news
| last = Pareles
| first = Jon
| coauthors =
| title = HEAVY METAL, WEIGHTY WORDS
| work = [[The New York Times]]
| place = USA
| page = 8
| language =
| publisher = The New York Times Company
| date = 10 July 1988
| url = http://www.nytimes.com/1988/07/10/magazine/heavy-metal-weighty-words.html?pagewanted=8
| accessdate = 14 November 2010}}</ref> on the U.S. [[Billboard 200|''Billboard'' 200]] album chart and was the band's first gold record for sales of over 500,000 copies. This was done without any radio airplay or the release of a music video. The album eventually was certified 6x platinum by the [[Recording Industry Association of America|RIAA]].<ref>{{cite web|title=Gold & Platinum|url=http://riaa.com/goldandplatinumdata.php?resultpage=1&table=SEARCH_RESULTS&action=&title=Master%20of%20Puppets&artist=Metallica&format=&de开发者_运维百科butLP=&category=&sex=&releaseDate=&requestNo=&type=&level=&label=&company=&certificationDate=&awardDescription=&catalogNo=&aSex=&rec_id=&charField=&gold=&platinum=&multiPlat=&level2=&certDate=&album=&id=&after=&before=&startMonth=1&endMonth=1&startYear=1958&endYear=2008&sort=Artist&perPage=25|publisher=RIAA|accessdate=2009-12-31}}</ref>
I think the usage of [^]
is misleading/not clear, I am not sure about its meaning.
(Because you are getting an error about a missing ]
, I would assume it opens a character class, the ^
is the negation of the class and the following ]
does not close the class, it is its first member. But because Regexr is using it differently I think the meaning differs in the different regex engines.)
You can try this one instead
{{Infobox[^{]*?({{[^}]*?}}[\s\S]*?)*}}
See it here on Regexr
I'd say the problem is with ^
, {
and }
characters not being escaped - you should try it with:
\{\{Infobox[\^]*?(\{\{[\^\{\}]*?\}\}\[^]*?)*\}\}
Edit to match any character with [^]
:
\{\{Infobox.*?(\{\{[.\{\}]*?\}\}\.*?)*\}\}
精彩评论