07-09-2013 10:29 AM
Hello.
I am trying to extract data from multiple text documents that go like this "abcdtwy teujh M: +1.2345678e000 mkgtd", and the number +1.2345678e000 is what I want to extract from the string. I can use string subset to separate the number from a single document, but the offset and string length of such data vary in different documents. Therefore, I am thinking of using match pattern to extract the entire string between "M:" and space.
I wonder if the match pattern function works in this situation. If so, what regular expression can I write to specify the string between "M:" and space?
Thanks a million .
Solved! Go to Solution.
07-09-2013 10:38 AM
Try, without the quotes, "M: ([^ ]+) "
The number you are looking for will be in submatch 1.
Cheers!
07-09-2013 11:05 AM
Thanks for replying to my question. I tried the code, but the number wasn't separated from the string; instead, the entire string was placed under "before substring".
Please inform me of any mistakes I might have made.Thank you.I appreciate all responses.
07-09-2013 11:38 AM
Try this as regex "\+?-?[.\d]+" (excluding quotes).
For your reference, find the attached EXAMPLE VI... this I made long back for my reference.
07-09-2013 11:41 AM
If your input string will always be the same as what you have provided -- "abcdtwy teujh M: +1.2345678e000 mkgtd" -- you could use the Scan from String function. You then will have several options for the format string input, the simplest of which is "%s %s %s %f %s" which will also do the string to number conversion for you.
07-09-2013 12:09 PM
I tried your test string again and the output worked out OK. Could you post some example(s) of when it fails ?
07-09-2013 12:43 PM
Hi 🙂
I realized that if I use match regular expression instead of match patter, the code "M: ([^ ]+)" works perfectly.
Thanks a lot.