[scilab-Users] Group definition in regular expression

CRETE Denis denis.crete at thalesgroup.com
Thu May 3 21:22:04 CEST 2012


Thank you so much, Samuel !

Denis

De : Samuel Gougeon [mailto:sgougeon at free.fr]
Envoyé : jeudi 3 mai 2012 21:06
À : users at lists.scilab.org
Objet : Re: [scilab-Users] Group definition in regular expression

Hello,

Le 03/05/2012 14:49, CRETE Denis a écrit :
Hello,

I am trying to use strsubst('E+31E+2',searchStr,replaceStr, 'r']) in order to insert a white space (or TAB delimiter) between the exponent ('3' in this example, but any digit in general) and the mantissa ('1' in this case, but any digit in general) of the first argument (a long series of numbers in scientific format). I did not figure out what replaceStr should look like to refer to groups - defined by patterns in parenthesis in searchStr. In this case, this would be used to defined a group with the exponent, with proper sign and magnitude between the symbol E and the inserted delimiter.

Thank you for any help or documentation on this topic.
Denis Crété
With strsubst(), the detection works, but not the substitution (nor the repetition):

-->strsubst('E+31E+2',"/(\-{0,1}[0-9](?:\.[0-9]*)*E)/"," \\1<file:///\\1>", 'r')
 ans  =
 E+3 \\1+2<file:///\\1+2>

You can do it in the following way:

myString = "E+31E+2-4.2E-3"
[v,s] = strsplit(myString,"/(\-{0,1}[0-9](?:\.[0-9]*)*E)/");
s=[ '' ; " "+s];
strcat(s+v)

giving

-->myString = "E+31E+2-4.2E-3"
 myString  =
 E+31E+2-4.2E-3

-->[v,s] = strsplit(myString,"/(\-{0,1}[0-9](?:\.[0-9]*)*E)/");
-->s=[ '' ; " "+s];
-->strcat(s+v)
 ans  =
 E+3 1E+2 -4.2E-3


For PCRE, a good pointer is:
http://www.php.net/manual/fr/reference.pcre.pattern.syntax.php

Regards
Samuel Gougeon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20120503/73ec1af7/attachment.htm>


More information about the users mailing list