带有前缀的图案的正则

发布于 2025-02-12 07:33:45 字数 818 浏览 1 评论 0原文

任何以下模式编写以下方式,

  1140×90.0
  軸距C(M/T)[648(534+114)×90.0]
  軸距E[643(529+114)×90.0]
  軸距E(M/T)[768(654+114)×90.0]enter code here
   軸距G[1098(984+114)×90.0]
    軸距G(M/T)[1223(1109+114)×90.0]

我想为我使用的

\[*\d*(\d\.[\d]+)?(\(\d+(\.[\d]+)?\+\d*([\d]*\d\.[\d]+)?\))?\×\d+([\d]*\.[\d]+)?\]*

在下面的模式下工作:

    [648(534+114)×90.0]
    [643(529+114)×90.0]
    [768(654+114)×90.0]
    1098(984+114)×90.0]
    [1223(1109+114)×90.0]
    890×90.0

现在我想在上述模式之前的任何单词上面的前缀,

    1140×90.0
    軸距C(M/T)[648(534+114)×90.0]
    軸距E[643(529+114)×90.0]
    軸距E(M/T)[768(654+114)×90.0]
    軸距G[1098(984+114)×90.0]`enter code here`
    軸距G(M/T)[1223(1109+114)×90.0]

请让我知道如何做到这一点

I want to write regex for any of the below pattern

  1140×90.0
  軸距C(M/T)[648(534+114)×90.0]
  軸距E[643(529+114)×90.0]
  軸距E(M/T)[768(654+114)×90.0]enter code here
   軸距G[1098(984+114)×90.0]
    軸距G(M/T)[1223(1109+114)×90.0]

I am using

\[*\d*(\d\.[\d]+)?(\(\d+(\.[\d]+)?\+\d*([\d]*\d\.[\d]+)?\))?\×\d+([\d]*\.[\d]+)?\]*

It is working for below patters:

    [648(534+114)×90.0]
    [643(529+114)×90.0]
    [768(654+114)×90.0]
    1098(984+114)×90.0]
    [1223(1109+114)×90.0]
    890×90.0

Now I want to prefix above any of words before above patterns

    1140×90.0
    軸距C(M/T)[648(534+114)×90.0]
    軸距E[643(529+114)×90.0]
    軸距E(M/T)[768(654+114)×90.0]
    軸距G[1098(984+114)×90.0]`enter code here`
    軸距G(M/T)[1223(1109+114)×90.0]

Please let me know how to do this

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眼眸里的快感 2025-02-19 07:33:45

您可以使用

[^\s\[\]]*\[*\d*\.?\d+(?:\(\d*\.?\d+\+\d*\.?\d+\))?×(?:\d*\.?\d+)?\]*

regex demo

详细信息

  • [^\ s \ [\]]* - 零或更多的chars和更高的chars and square brackets and whitespace
  • \ [* - 零或零或更多[ chars
  • \ d*\。?\ d+ - int/float号码
  • (?:\(\ d*\。?\ d+\+\ d*\。?\ d+\))? - 一个可选的序列
    • \( - a char
    • \ d*\。?\ d+ - int或float号码
    • \+ - a + char
    • \ d*\。?\ d+ - int或float号码
    • \) - a char
  • × - a × char
  • (?:\ d*\。?\ d+)? - 可选序列匹配int/float号码
  • <代码> \]* - 零或更多] chars。

You can use

[^\s\[\]]*\[*\d*\.?\d+(?:\(\d*\.?\d+\+\d*\.?\d+\))?×(?:\d*\.?\d+)?\]*

See the regex demo.

Details:

  • [^\s\[\]]* - zero or more chars other than square brackets and whitespace
  • \[* - zero or more [ chars
  • \d*\.?\d+ - an int/float number
  • (?:\(\d*\.?\d+\+\d*\.?\d+\))? - an optional sequence of
    • \( - a ( char
    • \d*\.?\d+ - an int or float number
    • \+ - a + char
    • \d*\.?\d+ - an int or float number
    • \) - a ) char
  • × - a × char
  • (?:\d*\.?\d+)? - an optional sequence matching an int/float number
  • \]* - zero or more ] chars.
慵挽 2025-02-19 07:33:45

不确定您是否需要捕获组,但是可以使用非贪婪的点。*?预先对模式进行预先匹配,直到遇到模式为止。

.*?\d+(\.\d+)?(\(\d+(\.\d+)?\+\d+(\.\d+)?\))?×\d+(\.\d+)?\]*

请参阅a regex demo

或以任何形式匹配任何类型的信函:

(?:\p{L}+(?:\([^()]*\))?)?\[?\d+(\.\d+)?(\(\d+(\.\d+)?\+\d+(\.\d+)?\))?×\d+(\.\d+)?\]*

Regex Demo

Not sure if you need the capture groups, but you can prepend the pattern with a non greedy dot .*? to match all before the pattern until you encounter the pattern.

.*?\d+(\.\d+)?(\(\d+(\.\d+)?\+\d+(\.\d+)?\))?×\d+(\.\d+)?\]*

See a regex demo

Or match for example optionally any kind of letter followed by an optional part between parenthesis:

(?:\p{L}+(?:\([^()]*\))?)?\[?\d+(\.\d+)?(\(\d+(\.\d+)?\+\d+(\.\d+)?\))?×\d+(\.\d+)?\]*

Regex demo

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文