I want to find text in files by regular expression using grep. This is the text I want to find, where is the white space before closing bracket:
{if sometexthere }
My command is:
grep -E -n "\{if[^\}]*[\s+]+\}" mydir/*
But it found lines where there is no white space before closing bracket, such as
{if sometexthere}
这应该工作:
grep -E "\{if[^\}]*?\s+\}"
You seem to have made the regex needlessly complex. Try:
grep "{if[^}]*\s}$" filename
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.