$re = '/(interface [a-zA-Z0-9 <>,\.\/*?[\s]]* \{|(@Immutable|@ThreadSafe|@NotThreadSafe)(.*[\n])*.*(class|enum) [a-zA-Z0-9\s<>,\.\/*?]* \{)/';
$str = 'package de.invesdwin.common.persistence.jpa.api.dao;
import java.io.Serializable;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.concurrent.ThreadSafe;
import javax.persistence.ElementCollection;
import javax.persistence.Embedded;
import javax.persistence.Query;
import javax.persistence.TypedQuery;
import org.apache.commons.lang3.mutable.MutableBoolean;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.support.SimpleJpaRepository;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ReflectionUtils.FieldCallback;
import de.invesdwin.common.lang.Assertions;
import de.invesdwin.common.lang.Reflections;
import de.invesdwin.common.persistence.jpa.PersistenceProperties;
import de.invesdwin.common.persistence.jpa.api.query.QueryConfig;
/**
* A DAO (DataAccessObject) is a special Repository that works for only one Entity. It implements default
* CRUD-Operations for it.
*
* JPA Entity attached/detaches status is automatically handled, so you don\'t need to care about that.
*
* @author subes
*/
@ThreadSafe
public abstract class ACustomIdDao<E, PK extends Serializable> extends ARepository implements IDao<E, PK> {
private final Class<E> genericType;
private final boolean deleteInBatchSupported;
private final QueryByExampleHelper<E, PK> queryByExampleHelper;
private Integer connectionBatchSize;
private SimpleJpaRepository<E, PK> delegate;
private String persistenceUnitName;
}
';
preg_match($re, $str, $matches, PREG_OFFSET_CAPTURE, 0);
// Print the entire match result
var_dump($matches);
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php