简体   繁体   中英

Rexex add <a href="tel: > </a> around all phone numbers in multiple .html pages

I have a lot of .html pages which contain phone numbers of this style:

html code: "phone: 1234-567-89123"

Now I want them all to be recognized as phone numbers if the .html page is rendered by a smartphone browser. Of course, the phone number is always different, except the state code 1234, this stays always the same. The length of the phone number with state code is always 12 numbers plus two hyphens.

I need a regex which converts the following:

"phone: 1234-567-89123" -> 
"phone: <a href="tel:123456789123">1234-567-89123</a>"

To do the replace I use this script , where the interface looks like this: 界面

So far I figgured out how to select my pattern:

1234-567-\d\d\d\d\d

now I need to replace that pattern with 
<a href="tel:1234567xxxxx">1234-567-xxxxx</a>

So I need to know how to copy the five digits into the replaced string.

The tool I am working with handles everything like I do static replacing with notepad++.

According to their GitHub, the tool uses:

String to search for or preg_replace() style regular expression.

If you find this:

"phone:\s*(\d+)-(\d+)-(\d+)"\s*-> 

You can replace it with this:

<a href="tel:$1$2$3">$1-$2-$3</a>

Note that $1 refers to the first capture group, and so on.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM