regex - Regular expression java read from properties -
i have task regular expressions in java , have question.
sentences = text.split(); how can pass () regular look regexp.properties file
regexp.declarative_sentence = "\\."; for example.
i utilize constant
public static final string declarative_sentence = "\\."; and create
sentences = text.split(declarative_sentence); but need read argument properties file. how can that? resource bundle example?
if i'm understanding correctly, want load regex value properties file.
to can utilize class within java called properties.
public properties getpropertiesfile(string location) throws ioexception { properties prop = new properties(); fileinputstream inputstream = null; seek { inputstream = new fileinputstream(location); prop.load(inputstream); } { if (inputstream != null) { inputstream.close(); } } homecoming prop; } you may have play fileinputstream , utilize getclass().getclassloader().getresourceasstream depending on you're case, should close.
here's how utilize function above:
properties prop = getpropertiesfile("regexp.properties"); string regex = prop.getproperty("declarative_sentence"); string[] ret = str.split(regex); you may have alter properties file location depending on configuration, , maybe fileinputstream if property file resource).
java regex string properties
No comments:
Post a Comment