I would like a regular expression which finds two consecutive words
for example
cancan
bonbon
chichi
I would like a regular expression which finds two consecutive words
for example
cancan
bonbon
chichi
You can try the following regular expression to match two consecutive words without any space:
grep -E '\b(\w+)\1\b' filename
grep -E '\b(\w+)\s+\1\b' filename
Above regular expression will match any two consecutive words that are the same.
\b
: Boundaries match word boundaries.(\w+)
: Captures one word.\s+
: Matches one or more whitespace characters.\1
: Refers back to the first captured word.https://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/
And
https://www.cyberciti.biz/faq/grep-regular-expressions/
Where can i learn about \s+ \1 \w+ ? Because they are not mentioned in the attached tutorials
Will update the page.
Could I do egrep “(\w+)(\w+)” instead of egrep “(\w+)\1 ” ?