Jump to content

Recommended Posts

i am trying to get number from string using this code :

#include <IE.au3>
$oIE = _IEAttach ("Edu.corner")
Local $aName = "Student name & Code:", $iaName = "0"
Local $oTds = _IETagNameGetCollection($oIE, "td")
For $oTd In $oTds
    If $oTd.InnerText = $aName Then
        $iaName = $oTd.NextElementSibling.InnerText
        $iGet = StringRegExpReplace($iaName, "\D", "")
     EndIf
Next
MsgBox(0, "", $iGet)

it was get number like 52503058

But, I want to get only student code 5250. (Different student have different code, sometime its 3 digits, Sometime 4)

area.JPG.fff7ca29de5bc44876cf45439e8e962b.JPG
 

Share this post


Link to post
Share on other sites

@jmp

You could use something like this:

ConsoleWrite(StringRegExp($oTd.InnerText, "[^:]+\h*:\h*(\d{3,4})\h*\(", $STR_REGEXPARRAYMATCH) & @CRLF)

By the way, what kind of sense do those variables names have?

$aName is not an array (the "a" should stand for array), and $iGet is not supposed to contain an integer value (the "i" should stand for integer), but a string.


Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites

@mikell
I meant to write it like this:

ConsoleWrite(StringRegExp($oTd.InnerText, "[^:]+\h*:\h*(\d{3,4})\h*\(", $STR_REGEXPARRAYMATCH)[0] & @CRLF)

 

2 minutes ago, mikell said:

(monday morning is painful)

You're definitely right! :)


Click here to see my signature:

Spoiler

Thoughts:

  • I will always thank you for the time you spent for me.
    I'm here to ask, and from your response, I'd like to learn.
    By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

/*--------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

ALWAYS GOOD TO READ:

 

Share this post


Link to post
Share on other sites
On 10/28/2019 at 1:08 PM, mikell said:

If this 3 or 4 digits number is the first one encountered inside the <td> then this may work

$Text = "ab 6 c 1234 def 5678 ghi"
Msgbox (0, "", StringRegExpReplace($Text, '.*?(\d{3,4}).*', "$1") )

@FrancescoDiMuro
$STR_REGEXPARRAYMATCH returns an array  (monday morning is painful) :)

@mikell Thank you very much. you are great.

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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By cruisepandey
      Hi, 
      I have a string like this : 
      Global $Msga = "urrent directory is /send.  (Submission of file with log number 29381077284 is confirmed)";
      I want to extract the number 29381077284  from the string. I did StringSplit to split based on "(" and then use space to reach there, But it's not a good choice. 
      Can anyone help me with regular expression to find the number from String using AutoIT. TIA
    • By ni3dprint
      Hi folks, 
      Thank you so much in advance for your help!  I've been using AUTOIT for manipulating gcode.  So far I've just worked through the excellent help examples and although I'm sure the resulting code is clumsy it has functioned  
      However now I'm trying to improve and advance things and I've stumbled across REGEX.. and I'm a bit stuck.  What I would like to be able to do is to 'move'/'transform' the gcode in a file and re-write it to a new file.  I only need to move it in one direction(X).  At the heart of this I need a script to extract all the X values and then ADD or SUBTRACT an adjustment factor to transform and rewrite the code accordingly.
      So far using an example script and an example input -
      Func Test2()
      Local $iMove = -4
          Local $sInput = '"G1 X45.036 Y6.934 F7800.000 G1 Z0.600 F7800.000 G1 F900 G1 X48.036 Y1.076 E0.58925"'
          Local $sOutput = StringRegExpReplace($sInput, '(?<=[X])\d+.\d+', '\0')
          Display($sInput, $sOutput)
      EndFunc   ;==>Test2
      This identifies the correct values i.e 45.036 and 48.036 but is there a way to dyamically adjust them before they are replaced, by for example a factor of -4 ($iMove above).  So far I can't seem to do math on the '\0' value i.e '\0'+ -4 ?
      Many thanks for your time and expertise!
       
    • By DannyJ
      I have this example string:
       
      2020-06-08 09:23:33 : abcdefghifjklm How to trim just the right part? Or how to trim this text right to left?
      I want to trim this string right to left until ' : '.
      In ohter words: I need the 'abcdefghifklm' text.
      I have tried StringTrimRight, but that requires 
      The number of characters to trim. Unfortunately StringSplit trims the left part of the strings.
       
       
    • By careca
      This is my take on string triggers, triggers on specific strings.
      Able to simple text pasting,
      opening links (as long as there's a www. http:\\ or https:\\ at the beggining)
      and is able to open applications, if there is a parameter in the parameter field, it uses it.
      Shows your external, lan, and gateway ip's.
      Able to change system volume by a set percentage, reading from the inputbox the number the user sets, if 0 or empty uses system default.
      I made this because the existing string trigger applications didn't do it for me.
      I did this for me, but if someone finds it useful, all the better.
    • By Colduction
      Hi guys!, i have a problem to convert Python code to AutoIt code, in fact i had not coded with Python yet!, this code is about permutation a string's case, i will be happy with your comments :)❤;

      Python code:
       
      # Python code to print all permutations # with respect to cases # Function to generate permutations def permute(inp): n = len(inp) # Number of permutations is 2^n mx = 1 << n # Converting string to lower case inp = inp.lower() # Using all subsequences and permuting them for i in range(mx): # If j-th bit is set, we convert it to upper case combination = [k for k in inp] for j in range(n): if (((i >> j) & 1) == 1): combination[j] = inp[j].upper() temp = "" # Printing current combination for i in combination: temp += i print(temp), # Driver code permute("Hello") # This code is contributed by Sachin Bisht
      My code in AutoIt:
      ; https://www.geeksforgeeks.org/permute-string-changing-case/ _PermuteCase("ABC") Func _PermuteCase($sText) If StringRegExp($sText, "^[A-Za-z]{1,}$") Then Local $iLength = StringLen($sText) ; Get length of the text. Local $iMaxPerm = 2 ^ $iLength ; Number of permutations is 2^n Local $sLow_Text = StringLower($sText) ; Converting string to lower case Local $asChrs = StringToASCIIArray($sLow_Text) ; Split the text into array of chars. For $i = 1 To $iMaxPerm Step 1 For $j = 0 To $asChrs[0] ;................................................... Next Next Else Return SetError(-1, 0, "Error: Input is incorrect!") EndIf EndFunc ;==>_PermuteCase  
       
       
       
       
       
      ====================== SOLUTION by @TheXman ======================
       
×
×
  • Create New...