w 和  正则表达式元字符的区别 [英] Difference between w and  regular expression meta characters

查看:38
本文介绍了w 和  正则表达式元字符的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能解释 w 正则表达式元字符之间的区别?我的理解是这两个元字符都用于单词边界.除此之外,哪个元字符对多语言内容有效?

Can anyone explain the difference between  and w regular expression metacharacters? It is my understanding that both these metacharacters are used for word boundaries. Apart from this, which meta character is efficient for multilingual content?

推荐答案

元字符  是一个锚点,类似于插入符号和美元符号.它在称为词边界"的位置匹配.此匹配的长度为零.

The metacharacter  is an anchor like the caret and the dollar sign. It matches at a position that is called a "word boundary". This match is zero-length.

三个不同的位置可以作为单词边界:

There are three different positions that qualify as word boundaries:

  • 在字符串的第一个字符之前,如果第一个字符是一个单词字符.
  • 在字符串的最后一个字符之后,如果最后一个字符是一个单词字符.
  • 在两个字符之间字符串,其中一个是单词字符,另一个不是单词字符.

简单地说: 允许您使用 word仅整个单词" 搜索代码>.单词字符" 是可用于构成单词的字符.所有不是单词字符"的字符都是非单词字符".

Simply put:  allows you to perform a "whole words only" search using a regular expression in the form of word. A "word character" is a character that can be used to form words. All characters that are not "word characters" are "non-word characters".

在所有风格中,字符 [a-zA-Z0-9_] 都是单词字符.这些也与简写字符类 w 匹配.在风味比较中显示 "ascii" 作为单词边界的风味仅将这些识别为单词字符.

In all flavors, the characters [a-zA-Z0-9_] are word characters. These are also matched by the short-hand character class w. Flavors showing "ascii" for word boundaries in the flavor comparison recognize only these as word characters.

w 代表单词字符",通常是[A-Za-z0-9_].请注意包含下划线和数字.

w stands for "word character", usually [A-Za-z0-9_]. Notice the inclusion of the underscore and digits.

B 的否定版本.B 不匹配的每个位置都匹配.实际上,B 匹配两个单词字符之间的任意位置以及两个非单词字符之间的任意位置.

B is the negated version of . B matches at every position where  does not. Effectively, B matches at any position between two word characters as well as at any position between two non-word characters.

W[^w] 的缩写,是 w 的否定版本.

W is short for [^w], the negated version of w.

这篇关于w 和  正则表达式元字符的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆