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

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -