java - Regex that matches a string and not a word -
i'd see internal libraries used in java project searching through code for
import com.mycompany.someproject.path.classname; let's project's title 'myproject'. regex match lines begin with
import com.mycompany. and exclude:
myproject.path... matched lines be:
import com.mycompany.tool.path.someclass; import com.mycompany.sallysproject.path.someotherclass; and exclude internal project imports:
import com.mycompany.myproject.*
this should work:
import com\.mycompany\.(?!myproject\.).* explanation:
import com\.mycompany\. - line must start import com.mycompany.. pretty self-explanatory; note need escape periods -- \. -- match periods, , not "any character".
(?!myproject\.) - called "negative lookahead". overall match succeed if pattern inside parentheses (except ?!) not match.
.* - after import com.mycompany. (except myproject.) matched.
Comments
Post a Comment