tags:

views:

178

answers:

1

Hi,

I'm trying to combine 2 different regex with the same names into one and got the error message like this:

Warning: preg_match(): Compilation failed: two named subpatterns have the same name at offset 276 ...

One regex looks like this:

'%<div class="artikkelen">[\s\S]*?<h2>(?P<title>[\s\S]*?)</h2>%'

The other looks like this:

'%<div id="article">[\s\S]*?<h1>(?P<title>[\s\S]*?)</h1>%'

I could combine them in the following way without problem:

'%(<div class="artikkelen">[\s\S]*?<h2>(?P<title>[\s\S]*?)</h2>|<div id="article">[\s\S]*?<h1>(?P<title2>[\s\S]*?)</h1>)%'

But I don't like this way because I use 2 names. I'm wondering whether there is a better way to solve this problem. Thanks in advance.

Best Regards, Box (boxoft...Simple & Great)

A: 

You could combine them like this instead:

%<div (class="artikkelen"|id="article")>[\s\S]*?<h[12]>(?P<title>[\s\S]*?)</h[12]>%

This is not exactly the same as it was before but might be good enough.

Greg
Thanks. It works.
boxoft