|
|
Regular Expression #8
Hi;
I have a string which likes:
Test: A, B, C
A , B , C are a float number with different length.
I want to extract value A.
Since the start ":" and end "," are clear. I wrote my code like:
idn1 = fscanf(s1) %idn1 is data coming from COMport
str= idn1;
pat = '\w*\:\w*\,'; % this is a pattern for finding number A
t = regexp(str, pat, 'match')
Goal is to save the value of A is 100 iteration in a file.
But my pattern is wrong and it gave me an empty output!
Do you have an idea?
Thanks for help
|
|
0
|
|
|
|
Reply
|
sb
|
11/23/2010 8:41:22 PM |
|
On 10-11-23 02:41 PM, sb bk wrote:
> I have a string which likes: Test: A, B, C
> A , B , C are a float number with different length.
>
> I want to extract value A.
> Since the start ":" and end "," are clear. I wrote my code like:
>
>
> idn1 = fscanf(s1) %idn1 is data coming from COMport
> str= idn1;
> pat = '\w*\:\w*\,'; % this is a pattern for finding number A
> t = regexp(str, pat, 'match')
>
>
>
> Goal is to save the value of A is 100 iteration in a file.
> But my pattern is wrong and it gave me an empty output!
> Do you have an idea?
You should not use \ before the colon or comma. It would also be better to use
+ instead of * as the repetition specifier.
But what I would do is
textscan(s1, '%*s%f%*[^\n]')
You do not need to put the colon in to the format as it will be considered
part of the first string. You do not need to put the comma in to the format
because it is not a valid character in a floating point number so that reading
of the floating point number would stop at the comma, and the comma would then
be absorbed by the final format specifier that will eat everything to the end
of the line.
|
|
0
|
|
|
|
Reply
|
Walter
|
11/23/2010 8:53:35 PM
|
|
|
1 Replies
296 Views
(page loaded in 0.04 seconds)
Similiar Articles: Using regular expressions to split a string - comp.lang.javascript ...Hi, I have a quick question. Using regular expressions, is it possible to split a string based on some special character (lets say &) but leave the s... Password Strength Regular Expression - comp.lang.javascript ...Hi I just need a regular expression for the condition that the password has to be a combination of alphabets and numbers. It cannot be only numbers n... Parsing Log records with regular expressions - comp.lang.ruby ...I have a log file which is text based which has records in two formats of the following form ` A|B|C|D\n A|B|C|D|E\n \n Exception\n \n \tstack... regsub (and regular expressions in general) trouble. - comp.lang ...Hello, This is related to my previous post "another newbie question, simple string operation?" My question changed quite a bit over the last few d... Perl Regular Expression (PRX) - comp.soft-sys.sasHi, Is there a PRX pattern that some one came across for to identify valid US Drivers License? Thanks!! ~Ram ... Test regex in KSH - comp.unix.shellHi, How can i test regular expression in KSH. My func is getting one parameter, i want to check if it is number. something like "^[0-9]+$" H... User-defined function and regexp - comp.lang.awkI don't know if it is a FAQ... Is-it possible to pass a regular expression to a user-defined function as parameter ? and if yes, can you give a simpl... list of regex special characters - comp.lang.pythonI am looking for a list of special character in python regular expressions that need to be escaped if you want their literal meaning. I searched a... Using regex's in Awk across linebreaks... - comp.lang.awk ...Hello All, I;m a newbie to Awk, though I am somewhat familiar with regular expressions. Would like to use Awk to extract data from a large text file... A programming problem. - comp.lang.awkWrite an awk program that reads quasi regular expressions from std-in and writes to std-out the set of strings in the language associated with the reg... Regular expression - Wikipedia, the free encyclopediaIn computing, a regular expression provides a concise and flexible means to "match" (specify and recognize) strings of text, such as particular characters, words, or ... Regular-Expressions.info - Regex Tutorial, Examples and Reference ...At Regular-Expressions.info you will find a wide range of in-depth information about a powerful search pattern language called regular expressions. 7/26/2012 12:30:38 AM
|
|
|
|
|
|
|
|
|