help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Use regex in ~/.emacs.d/init.el to match no_proxy.


From: Hongyi Zhao
Subject: Re: Use regex in ~/.emacs.d/init.el to match no_proxy.
Date: Wed, 7 Apr 2021 09:26:42 +0800

On Wed, Apr 7, 2021 at 12:56 AM Gregory Heytings <gregory@heytings.org> wrote:
>
>
> >>> As you can see, the "no_proxy" string is rather cumbersome, and I want
> >>> to express the following, but I still don't know what to do:
> >>>
> >>> "*.cn,localhost,10.0.0.0/8,127.0.0.0/8,172.16.0.0/12,192.168.0.0/16"
> >>>
> >>> Any hints will be highly appreciated.
> >>
> >> C-h i f regexp-opt RET
> >
>
> That should have been C-h S regexp-opt RET.

I still failed to use the above key sequence to call the regexp-opt
elisp function.

>
> (regexp-opt '("*.cn" "localhost" "10.0.0.0/8" "127.0.0.0/8" "172.16.0.0/12" 
> "192.168.0.0/16"))
>
> will return
>
> "\\(?:\\*\\.cn\\|1\\(?:0\\.0\\.0\\.0/8\\|27\\.0\\.0\\.0/8\\|72\\.16\\.0\\.0/12\\|92\\.168\\.0\\.0/16\\)\\|localhost\\)"

I obtained the above result by the following way:

M-S-: RET

Then paste the following into a small buffer at the bottom:

(regexp-opt '("*.cn" "localhost" "10.0.0.0/8" "127.0.0.0/8"
"172.16.0.0/12" "192.168.0.0/16"))

Hit RET and Emacs will give me the exactly same result as shown by you:

"\\(?:\\*\\.cn\\|1\\(?:0\\.0\\.0\\.0/8\\|27\\.0\\.0\\.0/8\\|72\\.16\\.0\\.0/12\\|92\\.168\\.0\\.0/16\\)\\|localhost\\)"


Additional Comment: I also tried to use the eshell method to call this
function, but failed as shown below:

M-x eshell RET

~ $ regexp-opt ("*.cn" "localhost" "10.0.0.0/8" "127.0.0.0/8"
"172.16.0.0/12" "192.168.0.0/16")

Wrong type argument: list-or-vector-p, "Invalid function: \"*.cn\""


> but I suspect this is not what you want, because:
>
> 1. you probably want to add a ^ at the beginning and a $ at the end of the
> regexp
>
> 2. you probably want to replace \\* by .+
>
> 3. regexp-opt does not understand that the IP address notation is a kind
> of wildcard, IOW, you probably do not want to match "10.0.0.0/8" but
> instead "10.0.0.1", "10.0.0.2", ..., "10.255.255.254", "10.255.255.255".

Thanks for your notes.

Regards,
HY
-- 
Assoc. Prof. Hongyi Zhao <hongyi.zhao@gmail.com>
Theory and Simulation of Materials
Hebei Polytechnic University of Science and Technology engineering
NO. 552 North Gangtie Road, Xingtai, China



reply via email to

[Prev in Thread] Current Thread [Next in Thread]