09-29-2010 03:45 AM
Sometimes, it was very easy to use the format string.
Frequently, the format string was not reliable to me.
I want to obtain two or three floating numbers from a string.
"Series 1: -0.02446 -0.02446 0.00031"
or "Series 2: -0.10868 0.00046"
For three numbers, I used "1:\s\s\s\s\s%s\s\s\s\s\s\s%s\s\s%s" as the format string.
1) Can you check my format string for 3 numbers?
2) How to prepare the regular expression for floating number? Is it inefficient to try with match pattern.vi for my purpose?
Labmaster.
09-29-2010 04:50 AM - edited 09-29-2010 04:52 AM
Regular Expressions can be your friend.
Here I used a Search and Replace String (set to Regular Expression) to remove the series number. The While Loop looks for a number, with or without a minus sign, and appends it to the Result array.
Read the Regexp like this:
The first part of the search looks for numbers like -1.23, the second part finds numbers like -.123.
Example attached.
09-29-2010 06:26 AM
09-29-2010 08:02 AM
Check this out. 🙂
/Y
02-22-2011 12:58 PM
How do you extract initials?
Let's say you have a name: Benjamin Roger Moore
and you want to get BRM
Here is how far I got:
Benjamin Moore
.+\s.
Any characters before the space and 1 character after: Benjamin M
How do I pick the first & last characters?
Actually, where I am stuck is how do you add to the regular expression?
regEx noob...
02-22-2011 01:17 PM - edited 02-22-2011 01:17 PM
Here is the basics. If you want to include punctuation and other stuff (like names with more than 4 names) that is left as an exercise for the user.
02-22-2011 02:09 PM - edited 02-22-2011 02:10 PM
How do you get the three string outputs at the bottom? I am using LV8.2. I don't think there was any change since then..
Based on your regEx, I was on the right track, but missed out on the * operator for *\s*.
At least I'm learning... 😉
BTW, ignore the shaded Match Regular Expression. I copied the code to Paint and it came out shaded...
02-22-2011 02:20 PM - edited 02-22-2011 02:24 PM
Just grab the bottom edge and drag down. Just like a build array or string concatenate. BTW, you will noticed the '?' in the middle of the regular expression to account for fewer than three names in the input name. If you needed this to work for much longer names I would probably build do the match in a loop to allow you to work for very long names.
02-22-2011 05:16 PM
02-22-2011 05:55 PM
You seem to have a lookahead assertion which allows a match of 0 items, basically always true. If my suspicion is correct, you can eliminate the assertion and make the regex even shorter (\b\w).
When I find myself facing a regex in a loop, I try to see if my old friend Search and Replace can help.