-1

I'm needing to get the information between /** and private ([var]); and parse it into an array for a js program.

I'm currently using this regex but having problems with it.

UPDATE: So some people have asked me what do I need this for, well to cut a long story short I need to mirror the information that the php crud generator sends through to the main class. Once I can get the annotations and the var names parsed into an array, Then I'll use that to generate (Something). So what I'm needing exactly is to first step: regex that gets everything between /** to private $(...); The problem is that the regex pull in the first annotation /** to the very last private var. so i just need something in my rexex that breaks each annotation up before further processing.

var myRegexp = /\/\*\*([\s\S\w\W\d\D]+)\*\/([\s]+)private ([\w\W\d\D]+);/g;
    match    = myRegexp.exec(entityString);

/**
     * @var string
     *
     * @ORM\Column(name="var_1", .....)
     */
    private $var1;

    /**
     * @var string
     *
     * @ORM\Column(name="document_path", ......)
     */
    private $documentPath;

    /**
     * @var string
     *
     * @ORM\Column(name="document_type", .....)
     */
    private $var2;

    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="NONE")
     */
    private $id;

    /**
     * @var \......\Entity\SomeEntity
     *
     * @ORM\ManyToOne(.....)
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(......)
     * })
     */
    private $var3;
TheMan68
  • 1,429
  • 6
  • 26
  • 48

1 Answers1

2
/\/\*\*([\s\S\w\W\d\D]+)\*\/([\s]+)

This part of your regex works good (https://regex101.com/r/cx2oww/1).

Now, if you want to get the private var after the doc you can use this :

\/\*\*([\s\S\w\W\d\D]+)\*\/([\s]+)private \$[\s\S\d\D]*\;

Link of rege101.com : https://regex101.com/r/cx2oww/2

You can increase this regex with ^$ for exemple to specified the beginning and end of your regex. I think your error came from ";" at the end of the private variable.

Mattasse
  • 1,023
  • 1
  • 11
  • 18
  • thank you for this. Its along the lines of what I need but not 100%. I preferably need to get everything between /** to the private $(...); and put each one into an array and then further process each entry to each each bit of data out that i need. – TheMan68 Dec 20 '16 at 09:29
  • @TheMan68 I thinks you can use an option like that `(?!\n)` and add capture group to get each private variable of your string – Mattasse Dec 20 '16 at 09:42
  • thank you very much. You were a great help – TheMan68 Dec 20 '16 at 10:36