简体   繁体   中英

What is the difference between “a{1}” and “a” in regex?

Some string was matched with the following `regex

([0-9]\s+){1}

Why did author use {1} in the end of regex?

Can I safely remove it?

Yes, there is no difference at all. Possibly it was left over from tweaks made while the regex was being built and tested.

在您的示例中, {1}将正则表达式匹配限制为仅一个整数或空格。

It is probably a leftover from debugging/writing the query when the author experimented with {1,2} or so.

Yes, you can remove it.

if it is the result of an interpreted code (log/debug coming from script for exemple) the 1 could be the value of a variable. If it is directly in a script, {1} is the default behavior so it is the same (but take longer to work due to extra interpreation to make by the parser)

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