J
J
Jake Taylor2021-04-24 13:45:48
Java
Jake Taylor, 2021-04-24 13:45:48

How to find a string using a regular expression containing a certain type of punctuation mark?

There are lines like:

1, 2, 3
1. 2. 3
1 - 2 - 3

How to find a string using a regular expression that contains a certain type of punctuation mark so that it looks like this:
1, 2, 3 (корректная, т.к. для разделения чисел используется один знак препинания)
1. 2. 3 (корректная, т.к. для разделения чисел используется один знак препинания)
1, 2. 3 (НЕ корректная, т.к. для разделения чисел используется два типа знаков препинания: точка и запятая)


Started to make such a regular expression\\p{P}*^[a-zA-Z]+

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dodo512, 2021-04-24
@n199a

String regex = "^\\d+([,.])\\h*\\d+(\\1\\h*\\d+)*$";

https://regex101.com/r/c4RYTj/1

S
SOTVM, 2021-04-24
@sotvm

\d+(\s*[,.]\s*\d+)*
ps
like this (corrected)))

^\s*\d+(\s*\.\s*\d+\s*)*$|^\s*\d+(\s*\,\s*\d+\s*)*$

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question