Regex matching imports of a class

Viewed 2280

I've been trying to write a regex to match the imports of a class. Let the class be

import static org.junit.Assert.*;
import org.
       package.
       Test;
import mypackage.mystuff;

The output should be [org.junit.Assert.*, org.package.Test, mypackage.mystuff]. I've been struggling with the line breaks and with regular expressions in general since I'm not that experienced with them. This is my current attempt:

((?<=\bimport\s)\s*([^\s]+ )*([a-z.A-Z0-9]+.(?=;))) 
6 Answers

This works good for me

import\s*((?:\w+[/./])+)

Related