説明
^(?:\+[0-9]{2}\s)?(?:\([0-9]{3}\)|[0-9]{3})\s[0-9]{3}(-|\s)[0-9]{2}\1[0-9]{2}
次の形式
- +38(093)937-99-92
- 093 937 99 92内の文字列にマッチする。この正規表現
- (093)937 99 92
問題です
例
ライブデモ
https://regex101.com/r/lM8hS0/1
説明
NODE EXPLANATION
----------------------------------------------------------------------
^ the beginning of a "line"
----------------------------------------------------------------------
(?: group, but do not capture (optional
(matching the most amount possible)):
----------------------------------------------------------------------
\+ '+'
----------------------------------------------------------------------
[0-9]{2} any character of: '0' to '9' (2 times)
----------------------------------------------------------------------
\s whitespace (\n, \r, \t, \f, and " ")
----------------------------------------------------------------------
)? end of grouping
----------------------------------------------------------------------
(?: group, but do not capture:
----------------------------------------------------------------------
\( '('
----------------------------------------------------------------------
[0-9]{3} any character of: '0' to '9' (3 times)
----------------------------------------------------------------------
\) ')'
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
[0-9]{3} any character of: '0' to '9' (3 times)
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------
\s whitespace (\n, \r, \t, \f, and " ")
----------------------------------------------------------------------
[0-9]{3} any character of: '0' to '9' (3 times)
----------------------------------------------------------------------
( group and capture to \1:
----------------------------------------------------------------------
- '-'
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
\s whitespace (\n, \r, \t, \f, and " ")
----------------------------------------------------------------------
) end of \1
----------------------------------------------------------------------
[0-9]{2} any character of: '0' to '9' (2 times)
----------------------------------------------------------------------
\1 what was matched by capture \1
----------------------------------------------------------------------
[0-9]{2} any character of: '0' to '9' (2 times)
----------------------------------------------------------------------
これは、 '+'末尾のです。 '(?:[0-9] {3})+'が必要になります。 – andlrc
Rubular.comと呼ばれる素晴らしいウェブサイト/ツールがあります。ページにregexを使用するためのいくつかのドキュメントがありますが、実際の宝石は正規表現やサンプルデータを入力し、すべてを解析する方法です。このような問題にはとても便利です。 –