How to convert a python regexp to java -
i need convert following python regexp java regexp:
regexp = re.compile(r"^(?p<prefix>(%s)(%s)?)\s?\b(?p<name>.+)" % ("|".join(array1), "|".join(array2)), re.ignorecase | re.unicode)
where array1 , 2 arrays of strings.
what did is:
string regexp = string.format("^(?<prefix>(%s)(%s)?)\\s?\\b(?<name>.+)", array1, array2); regexppattern = pattern.compile(regexp, pattern.case_insensitive);
but patternsyntaxexception: "unknown look-behind group near" in question mark of (%s)(%s)?
i don't understand question mark.
any suggestion on how translate java 1.6?
tons of things go wrong you.
the (?<
positive look-behind expression in java.
(?p<prefix>
named group in python, there no named groups in java.
string.format
%s
, array not produce |
joined strings array in python example.
first need join strings |
arrays manually. when have 2 strings, can do: regexppattern = pattern.compile(string.format("^((?:%s)(?:%s)?)\\s?\\b(.+)", string1, string2));
what prefix
group in python group 1 in java , name
group group 2.
Comments
Post a Comment