带有前缀的图案的正则
任何以下模式编写以下方式,
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
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
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.不确定您是否需要捕获组,但是可以使用非贪婪的点
。*?
预先对模式进行预先匹配,直到遇到模式为止。请参阅a regex demo
或以任何形式匹配任何类型的信函:
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.See a regex demo
Or match for example optionally any kind of letter followed by an optional part between parenthesis:
Regex demo