Posts: 128
Threads: 48
Joined: Jan 2007
Hi there,
I was wondering if there is a way to create something that what is found by a findrx can be 'split up' to a readable text and exported to a textbox.
The output of the findrx is one long line what is not handy to read so it has to be devided in the 'elements' Like:
Original: onetwothree
Becomes:
one
two
three
Is this possibe? i cannot get it done.....
TIA
Posts: 12,092
Threads: 142
Joined: Dec 2002
You probably use a str variable to get findrx output, like
str s
if(findrx("...abcdef..." "abcdef" 0 0 s)<0) ret
out s
You can use array instead:
ARRAY(str) a
if(findrx("...abcdef..." "(ab)(cd)(ef)" 0 0 a)<0) ret
out a[1]
out a[2]
out a[3]
a[0] will contain whole match (like s in the first example), a[1] - first part enclosed in (), and so on.
Posts: 128
Threads: 48
Joined: Jan 2007
Maybe i didn't give all necessary information...
The 'source text' comes from the clipboard and is pasted into s1 and i want to extract
\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}
when i use the example that you gave me it say's something about invalid index / wrong number of dimensions and this line cannot compile??
if findrx(s1 "\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}" 0 0 a)<0) ret
It gives a error:
Cannot make exe. Error 4, failed to compile.
Error in program: missing ( after function name, or ; after statement
ARRAY(str) a
is added to the macro....
Posts: 12,092
Threads: 142
Joined: Dec 2002
Number of ( and ) must be the same. Add ( after if.
In the regular expression string enclose parts that you want to extract.
Posts: 128
Threads: 48
Joined: Jan 2007
'In the regular expression string enclose parts that you want to extract' <= What do you mean by that, the regex gives what to search for and to populate the string with isn't it?
All i want is to search for this string and paste it in this string/array and have an option to make it readable, so far i came nothing further, the a[1] thing gives me errors
and the output is only one find, nothing in the rest of the text.
What am i doing wrong?
Posts: 12,092
Threads: 142
Joined: Dec 2002
Quote:'split up' to a readable text
? Why it is not readable?
To find all, use flag 4. Then array will have two dimensions. First - submatch number, second - match number.
int i
for i 0 a.len
;out a[1 i]
;out a[2 i]
;out a[3 i]
If you wnat to split to the numbers, the reg ex string should be
"(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})"
Quote:What do you mean by that, the regex gives what to search for and to populate the string with isn't it?
Yes, but it also can do more. If you enclose some parts in (), string parts matching these enclosed parts will be stored into array elements. That is, findrx also can be used to split strings.
Posts: 128
Threads: 48
Joined: Jan 2007
I adapted something but i get a 'invalid index' error, this is my 'code'
ARRAY(str) c
findrx(s1 "\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}" 0 4 c)
int z
for z 0 c.len
out c[1 z]
Any idea what is wrong with it,
Posts: 12,092
Threads: 142
Joined: Dec 2002
c[1 z] would contain 111 from a string like 111.222.333.444, if \d{1,3} would be enclosed into (). Since nothing is enclosed, index 1 is invalid.