Home > Net >  How to use regular expressions to extract the content of specific data, thank you
How to use regular expressions to extract the content of specific data, thank you

Time:05-13

One paragraph contains the following words:

Emmetropia to scatter light from nearby objects after eye inflectional imaging in the retina, can see close objects, call this function to adjust, to see up close goal, through the eye muscle - the ciliary muscle contraction, increase of intraocular lens bending, thereby enhancing the refractive power of the eye, make close objects formed in the retina, clear images, such as see nearly content
Regulate before left: 4.83 right: 4.62 eyes 5.03
After conditioning, left: 4.9 right: 4.84 eyes 5.0
There are many ways to adjust the vision such as cell phones and computers don't play for a long period of time, if there is an eye fatigue, can be appropriate to massage eye, see the distance, the green plants, much to the outdoor sports

Need them now:
Regulate before left: 4.83 right: 4.62 eyes 5.03
After conditioning, left: 4.9 right: 4.84 eyes 5.0

Inside six data according to pick up the order, haven't written a similar regular, please support, thank you

CodePudding user response:

String STR="before toning, left: 4.83 right: 4.62 to 5.03 after toning, eyes left: 4.9 right: 4.84 5.0" eyes.
The Regex Regex=new Regex (" (\ \ d + (\ \. \ \ d +)?) ");
Var matches=regex matches (STR);
List List=new List (a);
For (int I=0; i {
List. The Add (matches [I] the ToString ());
}

CodePudding user response:

 string SRC=https://bbs.csdn.net/topics/@ "emmetropia make divergent light from nearby objects after eye inflectional imaging in the retina, can see close objects, call this function to adjust, to see up close goal, through the eye muscle - the ciliary muscle contraction, increase of intraocular lens bending, thereby enhancing the refractive power of the eye, make close objects formed in the retina, clear images, such as see nearly content 
Regulate before left: 4.83 right: 4.62 eyes 5.03
After conditioning, left: 4.9 right: 4.84 eyes 5.0
There are many ways to adjust the vision such as cell phones and computers don't play for a long period of time, if there is an eye fatigue, can be appropriate to massage eye, see the distance, the green plants, much to the outdoor sports ";
System. Text. RegularExpressions. Match Match=System. Text. RegularExpressions. Regex. Match (SRC, @ "(? Before \ D + (n) tone? If (match. Success)
{
MessageBox. Show ($" before L: {match. Groups [r]. "before_left" Value} "+ Environment. The NewLine +
R before $" : {match. Groups [R]. "before_right" Value} "+ Environment. NewLine +
B: before $" {match. Groups [r]. "before_both" Value} "+ Environment. NewLine +
After $" L: {match. Groups [r]. "after_left" Value} "+ Environment. The NewLine +
R: after $" {match. Groups [R]. "after_right" Value} "+ Environment. NewLine +
B: after $" {match. Groups [r]. "after_both" Value} "+ Environment. NewLine);
}

CodePudding user response:

Match. Groups [" before_left "]. Value
Match. Groups [" before_right "]. Value
Match. Groups [" before_both "]. Value
Match. Groups [" after_left "]. Value
Match. Groups [" after_right "]. Value
Match. Groups [" after_both "]. Value

These are the results you want

CodePudding user response:

Thank you for your reply, your expression test for a long time, we have a risk, you actually find key respectively eyelid before and after the three sets of Numbers, but if the user in the process of description there are additional Numbers may be an error, such as user input:

Regulate before left: 4.83 right: 4.62 eyes 5.03 , there is error
After conditioning, left: 4.9 right: 4.84 eyes 5.0

You this analytical result is empty

refer to the second floor rabbit party - consultant reply:
 string SRC=https://bbs.csdn.net/topics/@ "emmetropia make divergent light from nearby objects after eye inflectional imaging in the retina, can see close objects, call this function to adjust, to see up close goal, through the eye muscle - the ciliary muscle contraction, increase of intraocular lens bending, thereby enhancing the refractive power of the eye, make close objects formed in the retina, clear images, such as see nearly content 
Regulate before left: 4.83 right: 4.62 eyes 5.03
After conditioning, left: 4.9 right: 4.84 eyes 5.0
There are many ways to adjust the vision such as cell phones and computers don't play for a long period of time, if there is an eye fatigue, can be appropriate to massage eye, see the distance, the green plants, much to the outdoor sports ";
System. Text. RegularExpressions. Match Match=System. Text. RegularExpressions. Regex. Match (SRC, @ "(? Before \ D + (n) tone? If (match. Success)
{
MessageBox. Show ($" before L: {match. Groups [r]. "before_left" Value} "+ Environment. The NewLine +
R before $" : {match. Groups [R]. "before_right" Value} "+ Environment. NewLine +
B: before $" {match. Groups [r]. "before_both" Value} "+ Environment. NewLine +
After $" L: {match. Groups [r]. "after_left" Value} "+ Environment. The NewLine +
R: after $" {match. Groups [R]. "after_right" Value} "+ Environment. NewLine +
B: after $" {match. Groups [r]. "after_both" Value} "+ Environment. NewLine);
}

CodePudding user response:

Actual test indicate if even add a comma after recuperation will be unable to extract to data

The
reference rabbit party - consultant reply: 3/f
match. The Groups [" before_left "]. The Value
Match. Groups [" before_right "]. Value
Match. Groups [" before_both "]. Value
Match. Groups [" after_left "]. Value
Match. Groups [" after_right "]. Value
Match. Groups [" after_both "]. Value

These are the results you want

CodePudding user response:

String SRC=https://bbs.csdn.net/topics/@ "emmetropia make divergent light from nearby objects after eye inflectional imaging in the retina, can see close objects, call this function to adjust, to see up close goal, through the eye muscle - the ciliary muscle contraction, increase of intraocular lens bending, thereby enhancing the refractive power of the eye, make close objects formed in the retina, clear images, such as see nearly content
Regulate before left: 4.83 right: 4.62 5.03 eyes,
After conditioning, left: 4.9 right: 4.84 5.0 eyes,
There are many ways to adjust the vision such as cell phones and computers don't play for a long period of time, if there is an eye fatigue, can be appropriate to massage eye, see the distance, the green plants, much to the outdoor sports ";
System. Text. RegularExpressions. Match Match=System. Text. RegularExpressions. Regex. Match (SRC, @ "(? Before \ D + (n) tone?
  •  Tags:  
  • C#
  • Related