Sign in to follow this  
Followers 0
Zorez

Need help for a parser

5 posts in this topic

Hello.

I have been working with autoit for some time now and I find it very good.

Recently I found out that I needed a parser and that I have now idea on how to do it (yes I have been searching but I seem to be unable find something that solve this)... :mellow:

I need a script that can "read" this:

X Something that doesn't matter that can include numbers too |Y|###|
^ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ ^~~~~~^
1                              2                               3

And then do this:

Part: 1. It need to convert the "X" letter (it is not always an "X", it's just an example) Into... Lets say "Ex. ". It is not that I can't convert it... I just can't find out to make the script read JUST that part.

Part: 2. Ignore part (as it doesn't matter).

Part: 3. It need to get the # (numbers) and nothing else from here (The letter(s) is again very important as there might be a |Z|###| that I don't care about). Lets just say the numbers bare 2543. Again the problem is to make it read JUST that part.

Then in the end put the "Ex. " and "2543" together to "Ex. 2543" (this line is simple, yes).

If anyone could help me with this it would be great! :(

Share this post


Link to post
Share on other sites



Hi Zorez,

This is just a simple example, not really a parser but it may do what you want.

$v_data = StringSplit("X Something that doesn't matter that can include numbers too |Y|###|","|")
IF IsArray($v_data) AND $v_data[0] THEN
 FOR $i = 1 TO $v_data[0]
    Consolewrite("ArrayPos "& $i &"="& $v_data[$i] & @CRLF)
 NEXT
 Consolewrite("E"& StringLeft($v_data[1],1) &"."& $v_data[3])   ; As requested. didn't really understand #1
ENDIF

With a bit of luck someone will come along and show you a regexp example, and really show ya how its done!

Res+

Vlad

Share this post


Link to post
Share on other sites

$string = "X Something that doesn't matter that can include numbers too like 9876|Y|2543|"
$result = StringRegExpReplace($string,"(.{1})\s.*\|.\|(\d*)\|", "E" & "\1." & " \2")
MsgBox(0,"",$result)

Share this post


Link to post
Share on other sites

Thanks for helping but it's not really what I am looking for.

You se the "Something that doesn't matter" part will always have a different name for every line.

Also the number will always change to something every line.

I need something that that can look at the first char in that line. If it's "X" (And maybe instantly convert the "X" and log the converted "X" > "Ex. " if it's better to do it instantly... Using a UDF I made myself to this project, "_Log($LogPath (just call it: $Log), $LogText)") then go and look for the |QID|###| (the ### is unknown for me as it change for every line(but the QID will always stay the same if "X" is an A, C and T char starting line)...

@ResNullius

Yours did almost work.

Only 2 things that dint:

If I change "X" to "A" it would write "EA. "

If I change the |Y|###| it dint work too.

I am not very familiar with "StringRegExpReplace". So I have no idea on how to fix this.

If it's still hard to understand what i mean (it's okay if it is... Even I am beginning to be confused when I read what I have written) then if you really want to help (would be nice :mellow: ), you can PM me for my MSN or something.

*Cheer* Mobius and ResNullius for some very good suggestions

Share this post


Link to post
Share on other sites

Thanks for helping but it's not really what I am looking for.

You se the "Something that doesn't matter" part will always have a different name for every line.

Also the number will always change to something every line.

I need something that that can look at the first char in that line. If it's "X" (And maybe instantly convert the "X" and log the converted "X" > "Ex. " if it's better to do it instantly... Using a UDF I made myself to this project, "_Log($LogPath (just call it: $Log), $LogText)") then go and look for the |QID|###| (the ### is unknown for me as it change for every line(but the QID will always stay the same if "X" is an A, C and T char starting line)...

@ResNullius

Yours did almost work.

Only 2 things that dint:

If I change "X" to "A" it would write "EA. "

If I change the |Y|###| it dint work too.

I am not very familiar with "StringRegExpReplace". So I have no idea on how to fix this.

If it's still hard to understand what i mean (it's okay if it is... Even I am beginning to be confused when I read what I have written) then if you really want to help (would be nice :mellow: ), you can PM me for my MSN or something.

*Cheer* Mobius and ResNullius for some very good suggestions

If this isn't it, then you need to seriously evaluate everything you are asking, and change how you're asking it. If it's confusing to you, it's surely going to be confusing to us.

You should also provide several "Before" possible string options that may come up, along with what they would look like after being converted.

$s_text = "X Something that doesn't matter that can include numbers too like 9876|Y|2543|"
$s_res = StringRegExpReplace($s_text,"(.{1}\s.*?)(\d*)(\|\z)", "Ex. " & "\2")
MsgBox(0,"",$s_res)

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0