Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
次の正規表現を使用して、アプリケーションの投稿から @username を解析しています。
'/(^|\s)#(\w*[a-zA-Z_]+\w*)/
の目的を誰か説明してくれませんか(^|\s)。その部分を省略したら?
(^|\s)
(^|\s)^文字列の先頭 ( ) または空白文字 ( )のいずれかと一致します\s。これはhallo#world、メンションとして一致しないようにするためです。
^
\s
hallo#world
その代わりに\b(単語境界) を使用します。セマンティクスはわずかに異なりますが、この場合は機能するはずです。
\b
(^|\s)行または文字列の先頭 ( ^) または ( |) 空白文字 ( \s)
|