Jump to content
Sign in to follow this  

Needing help with RegExp, details given

Recommended Posts

Hey there, seems I'm only posting when I need help >.< Kind of new to AutoIt so I will return any help I recieve in the future, promise!

Anyways, Im writing a script that will take in one of many different inputs and what I need to to is reduce it to base moves. I have spent almost a week trying to do this but keep having problems - any help give would be greatly appreciated.

Anyways, say for example I get the string


What I would need to do is first check if the string is like this, I was thinking RegEx like "\d//\d[(4)]"

Now what the (4) means is that I would have to reduce this to 4 times the text before the (4), like this.

a/b(4) -> a/b a/b a/b a/b

This would be the same for

a/b(3) -> a/b a/b a/b and a/b(2) -> a/b a/b

I would need to use the Function StringRegExpReplace I assume, but how would I go about formulating a replacment, What I mean is that - considering for example the function looked like this

$string = StringRegExpReplace($string, "\d//\d[(4)]", ******)

What would go where the *****'s are in order to convert the a/b(4) to a/b a/b a/b a/b

Its important to consider that a or b could be 2 digit numbers for example I would need to convert

1/1(4) -> 1/1 1/1 1/1 1/1

1/12(4) -> 1/12 1/12 1/12 1/12

12/12(4) -> 12/12 12/12 12/12 12/12

12/1(4) -> 12/1 12/1 12/1 12/1

Also, If you feel up to it, I have a few more strings that require similar evaluation.

I would need to reduce

a/b/c - > a/b b/c

a/b/c(2) - > a/b(2) b/c(2)

There would be no need to further evaluate a/b(2) b/c(2) as the above "a/b(2) -> a/b a/b" would be used.

a/b/c/d -> a/b b/c c/d

and finally.

a/b/c/d/e -> a/b b/c c/d d/e

I think thats pretty much all the reduction I would need to do, I just have no idea how to do it. As you can see I know what I may possibly have and I have an idea of how to use RegExp to check for these situations but as far as checking for if a number before and after the "/" is 1 or 2 digits long and then replacing the string with the corrosponding values i.e 1/2(2) -> 1/2 1/2, I have no idea.

Any help would be greatly appreciated, I know its a big thing to ask but I think I described it well enough that someone who knows what they are doing would see what needs to be done.

Thanks so much in advance.


Edited by marscom

Share this post

Link to post
Share on other sites

If the format is standard, then this is how I would approach it... but then I don't know RegExp very well (you may need to modify it if you need to break out the first part further)

$string = InputBox("Input", "Type in the string" & @LF & _
        "For Example: a/b(4) or 12/1(11)")
$move = StringLeft($string, StringInStr($string, "(") - 1)
$tmp = StringTrimLeft($string, StringInStr($string, "("))
$count = Int(StringTrimRight($tmp, 1))
$output = ""
For $i = 1 To $count
    $output &= $move & " "
MsgBox(0, "", "$input: " & $string & @LF & _
        "$move: " & $move & @LF & _
        "$count: " & $count & @LF & _
        "$output: " & $output)
Edited by SpookMeister

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Share this post

Link to post
Share on other sites

Thanks for the response Spookmeister! Just had an epiphany though and managed to get it working >.< lol, will post the code here so if anyone has a similar problem it will help. Goddam RegEx lol.

$n0 = ""
$n1 = ""
$n2 = ""
$step = 0

IF StringRegExp($clipboard,"\d\d?[//]\d\d?[//]\d\d?[(][2][)]",0) = 1 then

$arry[$step] = StringTrimRight($arry[$step],3)
$clipboard = StringRegExpReplace($clipboard,"\d\d?[//]\d\d?[//]\d\d?[(][2][)]",$arry[$step] & " " & $arry[$step],0)

$step = $step + 1


If StringRegExp($clipboard,"\d\d?[//]\d\d?[//]\d\d?[//]\d\d?[//]\d\d?",0) = 1 then
$n0 = StringRegExp($arry[$step],"\d\d?",3,1)
$clipboard = StringRegExpReplace($clipboard,"\d\d?[//]\d\d?[//]\d\d?[//]\d\d?[//]\d\d?",$n0[0] & "/" & $n0[1] & " " & $n0[1] & "/" & $n0[2] & " " & $n0[2] & "/" & $n0[3] & " " & $n0[3] & "/" & $n0[4],0)

$step = $step + 1


If StringRegExp($clipboard,"\d\d?[//]\d\d?[//]\d\d?[//]\d\d?",0) = 1 then
$n1 = StringRegExp($arry[$step],"\d\d?",3,1)
$clipboard = StringRegExpReplace($clipboard,"\d\d?[//]\d\d?[//]\d\d?[//]\d\d?",$n1[0] & "/" & $n1[1] & " " & $n1[1] & "/" & $n1[2] & " " & $n1[2] & "/" & $n1[3],0)

$step = $step + 1


If StringRegExp($clipboard,"\d\d?[//]\d\d?[//]\d\d?",0) = 1 then
$n2 = StringRegExp($arry[$step],"\d\d?",3,1)
$clipboard = StringRegExpReplace($clipboard,"\d\d?[//]\d\d?[//]\d\d?",$n2[0] & "/" & $n2[1] & " " & $n2[1] & "/" & $n2[2],0)

$step = $step + 1


$clipboard = StringRegExpReplace($clipboard,"\d\d?[//]\d\d?[(][4][)]","\0 \0 \0 \0",0)

$clipboard = StringRegExpReplace($clipboard,"\d\d?[//]\d\d?[(][3][)]","\0 \0 \0",0)

$clipboard = StringRegExpReplace($clipboard,"\d\d?[//]\d\d?[(][2][)]","\0 \0",0)

$clipboard = StringRegExpReplace($clipboard,"[(]\d[)]","",0)
Edited by marscom

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...