简体   繁体   中英

what is the difference between regex anchors \< and \>?

I just introduced myself to Regex anchors \\< and \\> . But no code I found to see how they are used actually in a code. So in that context can you help me to understand with the help of a code how differently they meet the purposes?

I found these from Cheat Sheet .

Thanks

They mean "start of word" ( \\< ) and "end of word" ( \\> ) where a "word" is an alphanumeric string. However, I don't think that Ruby supports them. They seem to be specific to a small subset of regex engines, especially POSIX EREs.

Most regex engines (including Ruby) only have word boundaries ( \\b ), and they match at the start or end of a word, and they are sufficient for most use cases.

For example, /bar\\b/ will match "bar" or (part of) "rebar" but not "barf" .

\\< means the starting character for an expression and \\> the character end. You can test the reqexp in ruby online at rubular.com .

For example, this should give you true:

"<Hello>" =~ /\<Hello\>/

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