Home > Net >  For a regular, matching part, at the same time to eliminate part of the content
For a regular, matching part, at the same time to eliminate part of the content

Time:12-27

Recently encountered a difficult problem, to parse of a program, the program will contain some data dimension calculation, so there will be a + - */symbols, also can have the iif expressions and & gt; 0=0, & gt; 1=1 the judgment of the characters, demand is: for each [Measures]. After the data information, [Measures]. After the first index, is the content of the parentheses in the back part dimensions, there may be multiple dimensions, separated by commas, is ultimately resolved to get all the metrics and dimensions,
For example:
([Measures]. [example], [KKK] Key [K]. & amp; [a long character string])
So:
[example]
[KKK] Key [K]. & amp; [a long character string]
is dimension
You need to the iif , the IIF , & gt; 0 , =0, & gt; 1 =1 and & lt; 0 , & lt; 1 this character, as well as the space character also will need to be removed, these characters are mostly outside the brackets, but sometimes exist within brackets, so within parentheses element in information should remain the same, just remove the above special characters outside of the [],
For example:
the iif (([Measures]. [this is an example (is the vast number of all Angle)] + [Measures]. [this is the second example (half Angle is the vast number of + 1 + 2 + 3)]), [a third example] [eat]. & amp; [1], NULL)

After regular treatment, need to:
[Measures]. [this is an example (is the vast number of all Angle)] [Measures]. [this is the second example (is half Angle of the vast number of + 1 + 2 + 3)], [a third example] [eat]. & amp; [1], a NULL

These data have rules to follow, can be summarized as: special characters need to remove the brackets, but a comma as undertake part of the expression, needs to retain,
In order to facilitate understanding, I am more than a few examples, the red part is the need to use regular replace,


Example 1:
the iif ( [Measures]. [the P4P - Obs - 03 _2_24-33, for example (test)] =0, NULL, [Measures]. [the P4P - Obs - 03 _1_ for particle] / [Measures]. [the P4P - Obs - 03 _2_24 - an example of 33] )
Results: [Measures]. [the P4P - Obs - 03 _2_24-33, for example (test)], NULL, [Measures]. [the P4P - Obs - 03 _1_ for particle] [Measures]. [the P4P - Obs - 03 _2_24 - an example of 33]

Example 2:
( [Measures] [META_ example], [ice-sugar gourd]. [r]. Delicious ice-sugar gourd & amp; [Obs - 10 _e1] )
Results: [Measures]. [META_ example], [ice-sugar gourd] [delicious ice-sugar gourd]. & amp; [Obs - 10 _e1]


Example 3 (is more, I put the metrics and dimensions, with different colors to distinguish, index is pink, dimension is purple) :
( [example] META_ example, [the] [r]. Whether clear & amp; [0] ) - ( [Measures]. [META_ earth earth] [the] [r]. Whether the vast & amp; [0] ) - (
(

[Measures]. [example] META_ example ,
[ok]. [example]. & amp; [0] ,
[one] example [example]. & amp; [BRKJ]
) * (
[Measures]. [example] META_ example ,
[eat]. [example example ok]. & amp; [0] ,
[sleep]. [example] example code & amp; (BFD) ,
[eat]. Examples [example]. & amp; [QQ02]
) + (
[Measures]. [example] META_ example ,
[CHI] example [example]. & amp; [0] ,
[HE] example [example]. & amp; [BR] ,
[PEN] [r]. HELLO & amp; [BN03]
)
)


Example 4:
the iif ( [Measures] [AT0_ for chestnut] =1 , NULL, [Measures]. [rr0_ results] / [Measures] [are _ just good] )



Regular study is really difficult! Research for a long time, can only write some simple, complex is to persist! Strives for the warrior who help, thank you very much!
  •  Tags:  
  • C#
  • Related