[英]Javascript - Create Regex Character Class
Is there a way to use javascript's regex engine to create a character class that matches with 有没有一种方法可以使用javascript的正则表达式引擎来创建与匹配的字符类
"
or "
或"
(one space before "
) or .
( "
前的一个空格)或.
or ,
or [SM_l]
or nothing (not the string "nothing" , just 0 characters) 或,
[SM_l]
或什么都不是(不是字符串“ nothing”,只有0个字符)
Background Context: This is going to be used as part of the solution to solve the problem presented in this post: Javascript - how to use regex process the following complicated string 背景信息:这将用作解决本文中所提出问题的解决方案的一部分: Javascript-如何使用正则表达式处理以下复杂的字符串
You don't a character class. 您不是角色类。 A character class [...]
denotes a match on every individual unit of data in it by which ["]+
means characters &
, q
, u
, o
, t
or ;
字符类[...]
表示其中每个数据单元的匹配,其中["]+
表示字符&
, q
, u
, o
, t
或;
in any order, with or without all characters: 任意顺序,带有或不带有所有字符:
"
&uot;
;&
What you need is called grouping. 您需要的称为分组。 You just need a |
您只需要一个|
inside a grouping construct to imply OR
conditions (that I also applied in an answer to your original question ) 在分组构造中表示“ OR
条件(我也将其应用于您原始问题的答案)
"
or"
或"
(one space before"
) ("
前的一个空格)
means [ ]?"
表示[ ]?"
.
or,
or[SM_l]
或者,
或[SM_l]
means (\\.|,|\\[SM_l])
that could be reduced to ([.,]|\\[SM_l])
表示可以简化为([.,]|\\[SM_l])
(\\.|,|\\[SM_l])
([.,]|\\[SM_l])
Putting all together you need: 将您需要的全部放在一起:
([ ]?"|[.,]|\[SM_l])?
Question mark denotes an optional match. 问号表示可选匹配项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.