Jump to content

String extract


Recommended Posts

Ok, string looks nice with replace OMXS308F to OMXS30-8FT.

How do i do to pick up just this value and store it in a variable, it's just this value OMXS30-8FT i want to have in a new variable.

I thought you wanted to replace the original value!!!?!?!

Link to comment
Share on other sites

I thought you wanted to replace the original value!!!?!?!

Not exactly, i get OMXS308F and want to write a new variable with OMXS30-8FT.

Maybe i'm confusing but this new variable OMXS30-8FT i will use later.

:)

Link to comment
Share on other sites

  • Moderators

Another problem is that OMXS308F is moving position depending on which alarm comes, so OMXS308F we can't get

by string right or something...

Classic case of "Tell us exactly what you need or would like to see happen" (most of us aren't mind readers :) ).

$s = '10:02 ORDER "sl) Omx Wampa Sellstop - Kl.10 - Röd - Okrypterat OMXS308F" kurs 951.0000' & @CRLF & _
'11:00 ORDER "sl) Omx Wampa Buystop - Kl.11 - Turkos - Okrypterat OMXS308F" kurs 953.5000' & @CRLF & _
'12:17 ORDER "sl) Omx Wampa Sellstop - Kl.11 - Rosa - Okrypterat OMXS308F" kurs 947.2500'
$aSRE = StringRegExp($s, "(OMXS\w+)", 1)
If IsArray($aSRE) = 0 Then Exit
$s = StringRegExpReplace($aSRE[0],'(OMXS\w{2})((\w{2}))', '\1-\2T')
MsgBox(0, 0, $s)

You would use 3 instead of 1 (In the StringRegExp) if you had different values in the string for OMXS, and then loop through them storing the new remade values as an array rather than a singular variable.

Edit:

Had to iterate something.

Edited by SmOke_N

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.

Link to comment
Share on other sites

I don't understand either, I can't get StringRegExpReplace to NOT capture groups:

I've had the same problem, but thought it was my nooby RegExp's:
$sString = "11AA22xx33CC"
$sString = StringRegExpReplace($sString, "(?:22)(.+)(?:33)", "BB")
ConsoleWrite("@error = " & @error & "  @extended = " & @extended & @LF)
ConsoleWrite("$sString = " & $sString & @LF); Expect "11AA22BB33CC"

I get: 11AABBCC

:)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

  • Moderators

Classic case of "Tell us exactly what you need or would like to see happen" (most of us aren't mind readers :) ).

$s = '10:02 ORDER "sl) Omx Wampa Sellstop - Kl.10 - Röd - Okrypterat OMXS308F" kurs 951.0000' & @CRLF & _
'11:00 ORDER "sl) Omx Wampa Buystop - Kl.11 - Turkos - Okrypterat OMXS308F" kurs 953.5000' & @CRLF & _
'12:17 ORDER "sl) Omx Wampa Sellstop - Kl.11 - Rosa - Okrypterat OMXS308F" kurs 947.2500'
$aSRE = StringRegExp($s, "(OMXS\w+)", 1)
If IsArray($aSRE) = 0 Then Exit
$s = StringRegExpReplace($aSRE[0],'(OMXS\w{2})((\w{2}))', '\1-\2T')
MsgBox(0, 0, $s)
Works to...

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.

Link to comment
Share on other sites

  • Moderators

I've had the same problem, but thought it was my nooby RegExp's:

$sString = "11AA22xx33CC"
$sString = StringRegExpReplace($sString, "(?:22)(.+)(?:33)", "BB")
ConsoleWrite("@error = " & @error & "  @extended = " & @extended & @LF)
ConsoleWrite("$sString = " & $sString & @LF); Expect "11AA22BB33CC"

I get: 11AABBCC

:)

$sString = "11AA22xx33CC"
$sString = StringRegExpReplace($sString, "(22)(.+)(33)", "\1BB\3")
ConsoleWrite("@error = " & @error & "  @extended = " & @extended & @LF)
ConsoleWrite("$sString = " & $sString & @LF); Expect "11AA22BB33CC"

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.

Link to comment
Share on other sites

  • Moderators
$sString = "11AA22xx33CC"
$sString = StringRegExpReplace($sString, "(22)(.+)(33)", "\1BB\3")
ConsoleWrite("@error = " & @error & "  @extended = " & @extended & @LF)
ConsoleWrite("$sString = " & $sString & @LF); Expect "11AA22BB33CC"oÝ÷ Ûú®¢×v+S)ä"«²ÚËZ®Ø§Ú.׫²Ö§vj+x1Ýjø§Æ¢vØ^iº/yÊ&¥ªÞ¶¬ëa¡Ûh¶¨¶«¢wÛz'ò¢è¶+m¢®¶­sbb33c·2Òb33³£"õ$DU"gV÷C·6Âö×v×6VÆÇ7F÷Ò¶ÂãÒ/fBÒö·'FW&BôÕ33bgV÷C²·W'2Sãb33²fײ5$Äbfײð¢b33³£õ$DU"gV÷C·6Âö×v×'W7F÷Ò¶ÂãÒGW&¶÷2Òö·'FW&BôÕ33bgV÷C²·W'2S2ãSb33²fײ5$Äbfײð¢b33³#£rõ$DU"gV÷C·6Âö×v×6VÆÇ7F÷Ò¶ÂãÒ&÷6Òö·'FW&BôÕ33bgV÷C²·W'2Crã#Sb33°¢b33c·7BÒ7G&æu&VtW&WÆ6Rb33c·2Âb33²â³òôÕ2b3#·w³'Òb3#·w³'Ò²b3#´GÂb3#¶EÒ²b33²Âb33²b3#³"Òb3#³5Bb33²¤×6t&÷ÂÂb33c·7B
Edited by SmOke_N

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.

Link to comment
Share on other sites

$sString = "11AA22xx33CC"
$sString = StringRegExpReplace($sString, "(22)(.+)(33)", "\1BB\3")
ConsoleWrite("@error = " & @error & "  @extended = " & @extended & @LF)
ConsoleWrite("$sString = " & $sString & @LF); Expect "11AA22BB33CC"
I see that's a work-around, but don't like it because it's just replacing the outer groups with themselves. Non-capturing groups should work!

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

  • Moderators

I see that's a work-around, but don't like it because it's just replacing the outer groups with themselves. Non-capturing groups should work!

:)

Do you have an example of some other RegExp language with RegExp Replace that "Non-Capturing" works? If so, that might be start.

Or is that a "I want it to work" statement?

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.

Link to comment
Share on other sites

Do you have an example of some other RegExp language with RegExp Replace that "Non-Capturing" works? If so, that might be start.

Or is that a "I want it to work" statement?

Perhaps a post in developer chat would be a good precursor to submitting a bug report, unless you can ask a dev.

Link to comment
Share on other sites

Do you have an example of some other RegExp language with RegExp Replace that "Non-Capturing" works? If so, that might be start.

Or is that a "I want it to work" statement?

Before settling on AutoIt to do my scripting at work, I played a little with Perl. I believe something like this would have worked:
$sVar =~ s/(?:22)(.+)(?:33)/BB/gi;
This is something like the *nix stream editor 'sed'. It says substitute match from the RegExp for "BB", do it global, and do it case-insensitive.

I don't have Perl loaded here any more to try it, so I could be wrong.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

  • Moderators

Before settling on AutoIt to do my scripting at work, I played a little with Perl. I believe something like this would have worked:

$sVar =~ s/(?:22)(.+)(?:33)/BB/gi;
This is something like the *nix stream editor 'sed'. It says substitute match from the RegExp for "BB", do it global, and do it case-insensitive.

I don't have Perl loaded here any more to try it, so I could be wrong.

:)

Well if it's any consolation, I would have expected it to work as well. I can only suggest making a ticket on it if you feel it's not the proper behavior. But I don't think comparing it to anything other than PCRE itself is going to fly here.

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.

Link to comment
Share on other sites

... I don't think comparing it to anything other than PCRE itself is going to fly here.

Well the point was PCRE = "Perl Compatible Regular Expressions", so I kind of was comparing it to itself.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

  • Moderators

Well the point was PCRE = "Perl Compatible Regular Expressions", so I kind of was comparing it to itself.

:)

If you read the "Compatibility" part in the PCRE.chm (provided in the source I believe), you'll see that it's by no means 100% Compatible.

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.

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...