java - Regex for matching alternating sequences -
i'm working in java , having trouble matching repeated sequence. i'd match like:
a.b.c.d.e.f.g.
and able extract text between delimiters (e.g. return abcdefg) delimiter can multiple non-word characters , text can multiple word characters. here regex far:
([\\w]+([\\w]+)(?:[\\w]+\2)*)
(doesn't work)
i had intended delimiter in group 2 regex , use replaceall on group 1 exchange delimiter empty string giving me text only. delimiter, cannot text.
thanks help!
replace (\w+)(\w+|$)
$1
. make sure global flag turned on.
it replaces sequence of word chars followed sequence of non-word-chars or end-of-line sequence of words.
string line = "am.$#%^ar.$#%^gho.$#%^sh"; line = line.replaceall("(\\w+)(\\w+|$)", "$1"); system.out.println(line);//prints name
Comments
Post a Comment