什么是前缀正则表达式?

时间:2022-06-29 22:35:01

I'm reading something that mentions prefix regular expressions, and sites as an example /^joey/

我正在阅读提到前缀正则表达式的内容,并将网站作为示例/ ^ joey /

What's a prefix regular expression? Does that mean it starts with a caret?

什么是前缀正则表达式?这是否意味着它以插入符号开头?

4 个解决方案

#1


-2  

It's not a standard term. Whoever wrote that obviously means a regex that matches only at the beginning of the target text, as the other responders have said. The caret is usually used for that purpose, but it can also mean the beginning of a logical line, if the match is being performed in multiline mode. Many regex flavors support an additional construct that matches the very beginning of the text regardless of the matching mode, \A being its usual form.

这不是一个标准术语。无论是谁写的,都显然意味着只在目标文本的开头匹配的正则表达式,正如其他响应者所说的那样。插入符号通常用于此目的,但如果在多行模式下执行匹配,它也可以表示逻辑行的开头。许多正则表达式都支持一个与文本的开头匹配的附加构造,而不管匹配模式是什么,\ A是它的通常形式。

For more details, read this.

有关详细信息,请阅读此内容。

#2


6  

A prefixed regular expression (PRE) is defined recursively

以递归方式定义前缀正则表达式(PRE)

  • Empty set ø end empty string ""- are PREs
  • 空集ø结空字符串“” - 是PRE

  • For each symbol a in alphabet, "a" is a PRE
  • 对于字母表中的每个符号a,“a”是PRE

  • If p and q are PREs denoting the regular sets P and Q, respectively, r is a regular expression denoting the regular set R such that e belongs to R, and x belongs to S, then the following expressions are also PREs:
    • p + q (union )
    • p + q(联盟)

    • xp (concatenation with symbol x on the left) .
    • xp(左侧符号x的连接)。

    • pr (concatenation with an e-regular on the right)
    • pr(与右边的e-regular连接)

    • p* (star) .
    • p *(星)。

  • 如果p和q分别是表示正则集P和Q的PRE,则r是表示规则集R的正则表达式,使得e属于R,并且x属于S,则以下表达式也是PRE:p + q (union)xp(与左边的符号x连接)。 pr(与右边的e-regular连接)p *(星号)。

This definition was taken from "Fast Text Searching for Regular Expressions or Automaton Searching on Tries" work by RICARDO A. BAEZA-YATES and GASTON H. GONNET

这个定义取自RICARDO A. BAEZA-YATES和GASTON H. GONNET的“快速文本搜索正则表达式或自动搜索试验”的工作。

In other words PRE means Regular Expression that language L has only strings with some fixed prefix. abc.* - is PRE (A|B)cd - is not PRE

换言之,PRE表示正则表达式,语言L仅具有带有一些固定前缀的字符串。 abc。* - 是PRE(A | B)cd - 不是PRE

#3


4  

in REGEX ^ at the start of a regex means, "Starts with"

在REGEX ^正则表达式的开头意味着,“开始于”

/^joey/

Would therefore match any string that starts with "joey" such as "joeyjoey" or "joey and jane"

因此匹配任何以“joey”开头的字符串,例如“joeyjoey”或“joey and jane”

#4


1  

The caret means that you match the start of a string for example /^joey/ will match "joey is there" since the string starts with "joey" but not "Is joey around?" since joey is in the middle of the sentence.

插入符表示你匹配字符串的开头例如/ ^ joey /将匹配“joey is there”,因为字符串以“joey”开头而不是“joey around?”因为乔伊正处于句子的中间。

#1


-2  

It's not a standard term. Whoever wrote that obviously means a regex that matches only at the beginning of the target text, as the other responders have said. The caret is usually used for that purpose, but it can also mean the beginning of a logical line, if the match is being performed in multiline mode. Many regex flavors support an additional construct that matches the very beginning of the text regardless of the matching mode, \A being its usual form.

这不是一个标准术语。无论是谁写的,都显然意味着只在目标文本的开头匹配的正则表达式,正如其他响应者所说的那样。插入符号通常用于此目的,但如果在多行模式下执行匹配,它也可以表示逻辑行的开头。许多正则表达式都支持一个与文本的开头匹配的附加构造,而不管匹配模式是什么,\ A是它的通常形式。

For more details, read this.

有关详细信息,请阅读此内容。

#2


6  

A prefixed regular expression (PRE) is defined recursively

以递归方式定义前缀正则表达式(PRE)

  • Empty set ø end empty string ""- are PREs
  • 空集ø结空字符串“” - 是PRE

  • For each symbol a in alphabet, "a" is a PRE
  • 对于字母表中的每个符号a,“a”是PRE

  • If p and q are PREs denoting the regular sets P and Q, respectively, r is a regular expression denoting the regular set R such that e belongs to R, and x belongs to S, then the following expressions are also PREs:
    • p + q (union )
    • p + q(联盟)

    • xp (concatenation with symbol x on the left) .
    • xp(左侧符号x的连接)。

    • pr (concatenation with an e-regular on the right)
    • pr(与右边的e-regular连接)

    • p* (star) .
    • p *(星)。

  • 如果p和q分别是表示正则集P和Q的PRE,则r是表示规则集R的正则表达式,使得e属于R,并且x属于S,则以下表达式也是PRE:p + q (union)xp(与左边的符号x连接)。 pr(与右边的e-regular连接)p *(星号)。

This definition was taken from "Fast Text Searching for Regular Expressions or Automaton Searching on Tries" work by RICARDO A. BAEZA-YATES and GASTON H. GONNET

这个定义取自RICARDO A. BAEZA-YATES和GASTON H. GONNET的“快速文本搜索正则表达式或自动搜索试验”的工作。

In other words PRE means Regular Expression that language L has only strings with some fixed prefix. abc.* - is PRE (A|B)cd - is not PRE

换言之,PRE表示正则表达式,语言L仅具有带有一些固定前缀的字符串。 abc。* - 是PRE(A | B)cd - 不是PRE

#3


4  

in REGEX ^ at the start of a regex means, "Starts with"

在REGEX ^正则表达式的开头意味着,“开始于”

/^joey/

Would therefore match any string that starts with "joey" such as "joeyjoey" or "joey and jane"

因此匹配任何以“joey”开头的字符串,例如“joeyjoey”或“joey and jane”

#4


1  

The caret means that you match the start of a string for example /^joey/ will match "joey is there" since the string starts with "joey" but not "Is joey around?" since joey is in the middle of the sentence.

插入符表示你匹配字符串的开头例如/ ^ joey /将匹配“joey is there”,因为字符串以“joey”开头而不是“joey around?”因为乔伊正处于句子的中间。