如何正则表达式(1.2.3)?

Lee*_*iss 3 php regex

我需要使用以下格式在文档中搜索一些文本:

(#.#.#) ex; (1.4.6)
Run Code Online (Sandbox Code Playgroud)

尽管这很简单,但它超出了我的正则表达能力.

Pru*_*Raj 7

您可以使用以下正则表达式:

\(\d{1,2}\.\d{1,2}\.\d{1,2}\)
Run Code Online (Sandbox Code Playgroud)

正则表达式可视化

DEMO

示例PHP:

<?php
$str = "(1.12.12) some text (1.1.1) some other text (1.1232.1) text";
preg_match_all('/\(\d{1,2}\.\d{1,2}\.\d{1,2}\)/',$str,$matches);
print_r($matches);
?>
Run Code Online (Sandbox Code Playgroud)

输出:

Array
(
    [0] => Array
        (
            [0] => (1.12.12)
            [1] => (1.1.1)
        )

)
Run Code Online (Sandbox Code Playgroud)

如果您想要可以有任意数字的位数(> 0),请使用以下正则表达式:

\(\d+\.\d+\.\d+\)
Run Code Online (Sandbox Code Playgroud)