Regex for matching alternating sequences

I work in Java and have difficulty repeating the sequence. I would like to map something like:

a.b.c.d.e.f.g.

and be able to extract text between the delimiters (for example, return abcdefg), where the delimiter can be several non-capital characters, and the text can be several characters of the word. Here is my regex:

([\\w]+([\\W]+)(?:[\\w]+\2)*)

(Does not work)

I intended to get the separator in group 2 with this regular expression, and then use replaceAll in group 1 to exchange the separator for an empty string giving me only text. I get a separator but cannot get all the text.

Thanks for any help!

+3
source share
4 answers

(\w+)(\W+|$) $1. , .

, .

String line = "Am.$#%^ar.$#%^gho.$#%^sh";
line = line.replaceAll("(\\w+)(\\W+|$)", "$1");
System.out.println(line);//prints my name
0

(\w+)\W+ $1

+1

String.split?

0

.

0

Source: https://habr.com/ru/post/1728147/


All Articles