Jump to content

Regex Help


rootx
 Share

Recommended Posts

Hi, I need help to write a regex.

possible cases:

Pos1,Pos2,Pos3

38/1,42/1,4367/100 <------------------- $ArLa[3]/(60*60)
  9/1 ,2341/100,8/1<------------------- $ArLa[2]/(60*60)

My target is check the /100, and if is true calculate coord in a specific way. Problem is when sometimes the position in this array changed but I need to found every time /100 to calculate 4367/100/(60*60) and ,2341/100/(60*60). THX

Dim $coord [2][3] = [["38/1", "42/1", "4367/100"],["9/1", "2332/100", "8/1"]]

For $x = 0 to UBound($coord)-1
    $lat = $coord[$x][0]&","&$coord[$x][1]&","&$coord[$x][2]
    ConsoleWrite($lat&@CR)
    ConsoleWrite(StringSplit($coord[$x][1], '/', $STR_ENTIRESPLIT)[2]&@CR);<------ work but not elegant
Next

I found A way ConsoleWrite(StringSplit($coord[$x][1], '/', $STR_ENTIRESPLIT)[2]&@CR)

Edited by rootx
Link to comment
Share on other sites

i'm not sure to understand....

Local $coord = ["38/1,42/1,4367/100", "9/1,2332/100,8/1"]
Local $sCalcExpression = "/(60*60)"

For $i = 0 To UBound($coord) - 1
    $sVal = StringRegExpReplace($coord[$i], ".*(?:^|,)(\d+\/100)\b.*", "$1")
    $sRes = Execute($sVal & $sCalcExpression)
    ConsoleWrite($sVal & $sCalcExpression & " = " & $sRes & @CRLF)
Next

 

Link to comment
Share on other sites

Sometimes it is easier not to use Regex.   Hope this helps.

#include <Array.au3>

Local $coord [2][3] = [["38/1", "42/1", "4367/100"],["9/1", "2332/100", "8/1"]]
ReDim $coord[UBound($coord)][UBound($coord, 2) + 1]
Local $Deg

For $i = 0 To UBound($coord) - 1
    For $j = 0 To UBound($coord, 2) - 2
        $sRes = Execute($coord[$i][$j]) / 60 ^ $j
        $Deg += $sRes
    Next
    $coord[$i][$j] = $Deg
    $Deg = 0
Next
_ArrayDisplay($coord, Default, Default, Default, Default, "Deg|Min|Sec|Total Num Degs")

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...