English 中文(简体)
需定期表达(RegEx)以取代XML中浮动点数
原标题:Need Regular Expression (RegEx) to replace floating-point numbers in XML

I m 采用《2010年视觉基本原理》,用XML文档进行编辑。 我想用一个零取代(典型的)非零浮动点数的项目。

开始:

<Body RelArmLen="1.234" RelLegLen="-9.876" RelWaist="-3.14159">

结束:

<Body RelArmLen="1.234" RelLegLen="0" RelWaist="-3.14159">

这些数字可能或可能不会开始――(主要)并且可能在数字的任一方面有任何数字。 如果起点值为零,则该数值可能或不一定为“0”或“0.0”或“0.00”。 无任何数值为+;缺乏——意味着积极。

(这个问题似乎涉及引文;我可以将其与RelLegLen=“前引书”和“RelLegLen=”之间的一切相匹配,而不只是属于RelLegLen的报价之间的浮动)

感谢!

最佳回答

从未经常使用XML。 从来没有。 你错了。 例如,一些拟议的“解决方案”将不能与使用单一报价作为限定词的特性相匹配,而是将“被引出”与在案文节点内出现的援引的特性相匹配。

This is an ideal candidate for XSLT, especially XSLT 2.0 which has regular expression support. Find the attributes you want to process with a template rule, then use the XPath 2.0 expression "castable as xs:double" to test if the format is floating point.

问题回答

请你这样做:

RelLegLen="[^"]*"

似乎你们想要将RelLegLen的任何东西改变为零。

为什么要尝试,以及用雷克语这样做? Net有一个可贵的XML教区,可以做你的工作。 http://msdn.microsoft.com/en-us/library/bb918016.aspx”rel=“nofollow” http://msdn.microsoft.com/en-us/library/bb918016.aspx

采用非电子配对:

/RelLegLen="(.*?)"/

这将从<代码>/RelLegLen=到下一个<编码>>>>。 该次表将包含你的浮标。

议题似乎已经完成,但也许有人会发现它很宝贵,即在2015年VS2015年,我用来寻找在扼杀和良好工作方面的硬编码数字:

"[-+]?d+(.d+)?"




相关问题
Is Shared ReadOnly lazyloaded?

I was wondering when I write Shared ReadOnly Variable As DataType = New DataType() Or alternatively Shared ReadOnly Variable As New DataType() Is it lazy loaded or as the instance initializes? ...

Entertaining a baby with VB.NET

I would like to write a little application in VB.NET that will detect a baby s cry. How would I get started with such an application?

Choose Enter Rather than Pressing Ok button

I have many fields in the page and the last field is a dropdown with list of values. When I select an item in a dropdown and press Enter, it doesn t do the "Ok". Instead I have to manually click on Ok ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

Set Select command in code

On button Click I want to Set the Select command of a Gridview. I do this and then databind the grid but it doesn t work. What am i doing wrong? protected void bttnView_Click(object sender, ...

Hover tooltip on specific words in rich text box?

I m trying to create something like a tooltip suddenly hoovering over the mouse pointer when specific words in the richt text box is hovered over. How can this be done?

热门标签