Bug 287396 - grep(1): BSD grep \w matches differently from GNU grep
Summary: grep(1): BSD grep \w matches differently from GNU grep
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 14.3-RELEASE
Hardware: amd64 Any
: --- Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on: 218806
Blocks: 230332
  Show dependency treegraph
 
Reported: 2025-06-09 15:20 UTC by OHARA Shigeki
Modified: 2025-06-10 13:54 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description OHARA Shigeki 2025-06-09 15:20:40 UTC
It seems that the \w character class in BSD grep matches differently compared to GNU grep.
Specifically, GNU grep's \w matches the underscore (_), whereas BSD grep does not.
Is this behavior intentional?


admin@freebsd14:~ $ cat /etc/os-release
NAME=FreeBSD
VERSION="14.3-RELEASE"
VERSION_ID="14.3"
ID=freebsd
ANSI_COLOR="0;31"
PRETTY_NAME="FreeBSD 14.3-RELEASE"
CPE_NAME="cpe:/o:freebsd:freebsd:14.3"
HOME_URL="https://FreeBSD.org/"
BUG_REPORT_URL="https://bugs.FreeBSD.org/"
admin@freebsd14:~ $ echo $LANG
C.UTF-8
admin@freebsd14:~ $ grep --version
grep (BSD grep, GNU compatible) 2.6.0-FreeBSD
admin@freebsd14:~ $ echo a_ | grep -o '\w*'
a
admin@freebsd14:~ $ ggrep --version
ggrep (GNU grep) 3.11
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Mike Haertel and others; see
<https://git.savannah.gnu.org/cgit/grep.git/tree/AUTHORS>.

grep -P uses PCRE2 10.45 2025-02-05
admin@freebsd14:~ $ echo a_ | ggrep -o '\w*'
a_
admin@freebsd14:~ $
Comment 1 Wolfram Schneider freebsd_committer freebsd_triage 2025-06-10 13:54:14 UTC
The cool kids use ripgrep or ugrep.

echo a_ | rg -o '\w*'
a_

echo a_ | ug -o '\w*'
     1:	_