import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^[\\w\\d-]*(?=\\=)";
final String string = "# This file may be used to create an environment using:\n"
+ "# $ conda create --name <env> --file <this file>\n"
+ "# platform: osx-64\n"
+ "absl-py=0.7.1=py36_0\n"
+ "appnope=0.1.0=py36_1000\n"
+ "asn1crypto=0.24.0=py36_1003\n"
+ "astor=0.7.1=py_0\n"
+ "attrs=19.1.0=py_0\n"
+ "backcall=0.1.0=py_0\n"
+ "bleach=3.1.0=py_0\n"
+ "blinker=1.4=py_1\n"
+ "boto=2.49.0=py_0\n"
+ "boto3=1.9.210=py_0\n"
+ "botocore=1.12.210=py_0\n"
+ "bz2file=0.98=py_0\n"
+ "c-ares=1.15.0=h01d97ff_1001\n"
+ "ca-certificates=2019.6.16=hecc5488_0\n"
+ "certifi=2019.6.16=py36_1\n"
+ "cffi=1.12.3=py36hccf1714_0\n"
+ "chardet=3.0.4=py36_1003\n"
+ "cryptography=2.7=py36h212c5bf_0\n"
+ "cycler=0.10.0=py_1\n"
+ "cymem=2.0.2=py36h6de7cb9_0\n"
+ "cython-blis=0.2.4=py36h01d97ff_1\n"
+ "decorator=4.4.0=py_0\n"
+ "defusedxml=0.5.0=py_1\n"
+ "docutils=0.15.2=py36_0\n"
+ "en-core-web-lg=2.1.0=pypi_0\n"
+ "en-core-web-md=2.1.0=pypi_0\n"
+ "en-core-web-sm=2.1.0=pypi_0\n"
+ "entrypoints=0.3=py36_1000\n"
+ "freetype=2.10.0=h24853df_1\n"
+ "funcy=1.13=py_0\n"
+ "future=0.17.1=py36_1000\n"
+ "gast=0.2.2=py_0\n"
+ "gensim=3.4.0=py36h1de35cc_0\n"
+ "grpcio=1.22.0=py36h6ef0057_0\n"
+ "h5py=2.9.0=nompi_py36h6248fd5_1104\n"
+ "hdf5=1.10.5=nompi_h0cbb7df_1100\n"
+ "idna=2.8=py36_1000\n"
+ "ipykernel=5.1.2=py36h5ca1d4c_0\n"
+ "ipython=7.7.0=py36h5ca1d4c_0\n"
+ "ipython_genutils=0.2.0=py_1\n"
+ "jedi=0.15.1=py36_0\n"
+ "jinja2=2.10.1=py_0\n"
+ "jmespath=0.9.4=py_0\n"
+ "joblib=0.13.2=py_0\n"
+ "jpeg=9c=h1de35cc_1001\n"
+ "jsonschema=3.0.2=py36_0\n"
+ "jupyter_client=5.3.1=py_0\n"
+ "jupyter_core=4.4.0=py_0\n"
+ "keras-applications=1.0.7=py_1\n"
+ "keras-preprocessing=1.0.9=py_1\n"
+ "kiwisolver=1.1.0=py36h770b8ee_0\n"
+ "libblas=3.8.0=12_openblas\n"
+ "libcblas=3.8.0=12_openblas\n"
+ "libcxx=8.0.0=4\n"
+ "libcxxabi=8.0.0=4\n"
+ "libffi=3.2.1=h6de7cb9_1006\n"
+ "libgfortran=3.0.1=0\n"
+ "liblapack=3.8.0=12_openblas\n"
+ "libopenblas=0.3.7=hd44dcd8_1\n"
+ "libpng=1.6.37=h2573ce8_0\n"
+ "libprotobuf=3.9.1=hfbae3c0_0\n"
+ "libsodium=1.0.17=h01d97ff_0\n"
+ "libtiff=4.0.10=hd08fb8f_1003\n"
+ "lz4-c=1.8.3=h6de7cb9_1001\n"
+ "markdown=3.1.1=py_0\n"
+ "markupsafe=1.1.1=py36h1de35cc_0\n"
+ "matplotlib-base=3.1.1=py36h3a684a6_1\n"
+ "mistune=0.8.4=py36h1de35cc_1000\n"
+ "murmurhash=1.0.0=py36h0a44026_0\n"
+ "nbconvert=5.6.0=py_0\n"
+ "nbformat=4.4.0=py_1\n"
+ "ncurses=6.1=h0a44026_1002\n"
+ "nltk=3.4.4=py_0\n"
+ "notebook=6.0.0=py36_0\n"
+ "numexpr=2.7.0=py36h86efe34_0\n"
+ "numpy=1.17.0=py36h6b0580a_0\n"
+ "oauthlib=3.0.1=py_0\n"
+ "olefile=0.46=py_0\n"
+ "openssl=1.1.1c=h01d97ff_0\n"
+ "pandas=0.25.0=py36h86efe34_0\n"
+ "pandoc=2.7.3=0\n"
+ "pandocfilters=1.4.2=py_1\n"
+ "parso=0.5.1=py_0\n"
+ "patsy=0.5.1=py_0\n"
+ "pexpect=4.7.0=py36_0\n"
+ "pickleshare=0.7.5=py36_1000\n"
+ "pip=19.2.2=py36_0\n"
+ "plac=0.9.6=py36_0\n"
+ "preshed=2.0.1=py36h6de7cb9_0\n"
+ "prometheus_client=0.7.1=py_0\n"
+ "prompt_toolkit=2.0.9=py_0\n"
+ "protobuf=3.9.1=py36h6de7cb9_0\n"
+ "ptyprocess=0.6.0=py_1001\n"
+ "pycountry=19.8.18=pypi_0\n"
+ "pycparser=2.19=py36_1\n"
+ "pygments=2.4.2=py_0\n"
+ "pyjwt=1.7.1=py_0\n"
+ "pyopenssl=19.0.0=py36_0\n"
+ "pyparsing=2.4.2=py_0\n"
+ "pyrsistent=0.15.4=py36h01d97ff_0\n"
+ "pysocks=1.7.0=py36_0\n"
+ "python=3.6.7=h94afb7f_1005\n"
+ "python-dateutil=2.8.0=py_0\n"
+ "pytz=2019.2=py_0\n"
+ "pyzmq=18.0.2=py36hee98d25_2\n"
+ "readline=8.0=hcfe32e1_0\n"
+ "requests=2.22.0=py36_1\n"
+ "requests-oauthlib=1.2.0=py_0\n"
+ "retrying=1.3.3=py_2\n"
+ "s3transfer=0.2.1=py36_0\n"
+ "scipy=1.3.1=py36hab3da7d_2\n"
+ "seaborn=0.9.0=py_1\n"
+ "send2trash=1.5.0=py_0\n"
+ "setuptools=41.0.1=py36_0\n"
+ "simplejson=3.16.1=py36h470a237_0\n"
+ "six=1.12.0=py36_1000\n"
+ "smart_open=1.8.4=py_0\n"
+ "snowballstemmer=1.9.0=py_0\n"
+ "sortedcollections=1.1.2=py_0\n"
+ "sortedcontainers=2.1.0=py_0\n"
+ "spacy=2.1.8=py36h770b8ee_0\n"
+ "sqlite=3.29.0=hb7d70f7_0\n"
+ "srsly=0.0.7=py36h6de7cb9_0\n"
+ "statsmodels=0.10.1=py36heacc8b8_0\n"
+ "sumy=0.8.1=pypi_0\n"
+ "tensorboard=1.13.1=py36_0\n"
+ "tensorflow=1.13.1=py36_1\n"
+ "tensorflow-estimator=1.13.0=py36h24bf2e0_0\n"
+ "termcolor=1.1.0=py_2\n"
+ "terminado=0.8.2=py36_0\n"
+ "testpath=0.4.2=py_1001\n"
+ "thinc=7.0.8=py36h770b8ee_0\n"
+ "tk=8.6.9=h2573ce8_1002\n"
+ "tornado=6.0.3=py36h01d97ff_0\n"
+ "tqdm=4.33.0=py_0\n"
+ "traitlets=4.3.2=py36_1000\n"
+ "tweepy=3.8.0=py_0\n"
+ "urllib3=1.25.3=py36_0\n"
+ "wasabi=0.2.2=py_0\n"
+ "wcwidth=0.1.7=py_1\n"
+ "webencodings=0.5.1=py_1\n"
+ "werkzeug=0.15.5=py_0\n"
+ "wheel=0.33.4=py36_0\n"
+ "xz=5.2.4=h1de35cc_1001\n"
+ "zeromq=4.3.2=h6de7cb9_2\n"
+ "zlib=1.2.11=h01d97ff_1005\n"
+ "zstd=1.4.0=ha9f0a20_0";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(string);
while (matcher.find()) {
System.out.println("Full match: " + matcher.group(0));
for (int i = 1; i <= matcher.groupCount(); i++) {
System.out.println("Group " + i + ": " + matcher.group(i));
}
}
}
}
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 Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html