English 中文(简体)
定期表达接触特定群体
原标题:Regular expression to get a specific group

我有这一表述:(D)(--->?)d+(d+)? 这一工作涉及大多数模式。 但是,这种模式在证明我根本无法得到。 Im 使用 Java和春

也就是说,适用以下规定:

$1.0?8S0.0H692.8Q651.7u3.3o294.8n0t32.6s0R0.0P0.0Y114.9|136.3%1N-22.08930501E-48.05973392D692.374U0.0V0.00O0.0I6G0.20F12h0.000v0.000x1y1a24.0412e5.0690b0.00l0.0000r0.0000f0p4¨[email protected]º0|0|0|0=51.9988B1.0#0

It s is simply, get the first character that s not a digit, after get the plus or minus character, after get the number. if exists a float point, get the point with the remnant numbers. This is the common pattern. The result is something like:

  • $ - 1.0
  • ? - 8
  • S - 0.0
  • = - 51.9988
  • t - 32.6

在哈希姆普省这样做之后。

但是,有一部分人用管道接通:

  • <>斯特凡>

  • º0|0|0|0

Because of the firts rule, this is interpreted as another value.

我想要改变这一规范。 取得这样的成就:

  • Y - 114.9 | 136.3
  • º - 0 | 0 | 0 | 0

之后,我会形成一种逻辑,把这一点放在一个阵列中。

感谢任何人的帮助

最佳回答

您可以将<条码>D(与数字以外的任何特性相匹配)改为更具体的、否定的特性类别<条码>[代号+-],排除更多的特性。

重复使用管道 /code> 果园和数字,则可以选择性地重复非捕获组。

如果你不想拿到个别部分,那么你就可以完全排除这些俘虏团体,而只是获得完全匹配。

您可以使用:

[^ds.+-][-+]?d+(?:.d+)?(?:|d+(?:.d+)?)*

部分的格局如下:

  • [^ds.+-] Match a single character other than a digit, whitspace char or one of . + -
  • [-+]? Match an optional - or +
  • d+(?:.d+)? Match 1+ digits with an optional decimal part
  • (?:|d+(?:.d+)?)* Optionally repeat | followed by 1+ digits with an optional decimal part

regex demo

问题回答

D的非数字也应排除空间。 因此,将数字和白色空间排除在外。 如果各要素之间有空间,你也应加以检查。 您掌握数据的情况如下:

([^0-9s]s*?[-|+]s*?[0-9]+(?:[.][0-9]+)?)

按要素分列的解释

 ([^0-9s]              non-digit and not space
    s*?                possibly space
    [-|+]               -/+
    s*?                possibly space
    [0-9]+(?:[.][0-9]+)?)    the number

获取多个数量(有管道)

([^0-9s]s*?[-|+]s*?[0-9]+(?:[.][0-9]+)?(?:s*?|s*?[0-9]+(?:[.][0-9]+)?)*?)

按要素分列的解释

 ([^0-9s]                    non-digit and not space
 s*?                         possibly space
 [-|+]                        - / +
 s*?                         possibly space
 [0-9]+(?:[.][0-9]+)?         a number 
 (?:s*?|s*?[0-9]+(?:[.][0-9]+)?)*?)  possibly multiple of  |number 




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...