Jump to content

possible with string reg exp?


Recommended Posts

Martin your code isnt actually founding the chars in the string

Doesn't it? Can you give an example of it failing?

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

#include <Array.au3>
$a = _StringInStrRandom ("MX0G2H883H7426288620TS", "G283H88620TS")

_ArrayDisplay($a)

Func _StringInStrRandom ($sSearchString, $sCharsString)
   Local $i, $Err = 0, $a
  Local $aS=stringsplit($sCharsString,''),$newS
  
  for $i = 1 to $aS[0]
      $newS &= ".*" & $aS[$i]
  Next
   $newS &= ".*"
   ConsoleWrite($newS & @CRLF)
   
   $a = StringRegExp($sSearchString,"(" & $newS & ")", 1) 
  Return $a
EndFunc; ==> _StringInStrRandom

Link to comment
Share on other sites

  • Moderators

its working so far.. curious to see if there is a case where it wouldnt work..

Edit:

Here, try this:

MsgBox (0, "", _String_InStrRandom("MX0G2H883H7426288620TS?1539Z", "G283H88620TS?Z"))

Func _String_InStrRandom($s_search_str, $s_char_str)
    Return StringRegExp($s_search_str, StringRegExpReplace(StringRegExpReplace( _
        $s_char_str, "(.)", "\.*?$1"), "(\.\*\?)(\.|\||\*|\?|\+|\(|\)|\{|\}|\[|\]|\^|\$|\\)", "$1\\$2"))
EndFunc

Edit2:

Ok, I'm done!

This one follows the same idea that Martin was doing... Seems to work, but added case sensitivity option:

Func _String_InStrRandom($s_search_str, $s_char_str, $v_case = 0)
    Local $s_case = "(?i)"
    If $v_case Then $s_case = ""
    Return StringRegExp($s_search_str, $s_case & StringRegExpReplace($s_char_str, "(.)", "\.*?$1\.*?"))
EndFunc
Ok Martin, I'll see your 10 lines, and make it 5 less :party: (your turn :) ) 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'm wrong, I misinterpreted Martin's code, I thought the OP wanted to find the string and not if it mateches or not, forgive me.

No problem oMBRa, it doesn't seem like a terrible sin to me :)

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

  • 3 months later...

can anyone help me figure out what this would like like in a SQL query?

(including case sensitivity)

SELECT AssetTag,Model,SerialNumber FROM aInventoryInfo WHERE AssetTag LIKE ____

Thanks!!!!!!!!

Maybe something like this

MsgBox (0, "", _StringInStrRandom ("MX0G2H883H7426288620TS", "G283H88620TS"))

Func _StringInStrRandom ($sSearchString, $sCharsString)
   Local $i, $Err = 0
  Local $aS=stringsplit($sCharsString,''),$newS
  
  for $i = 1 to $aS[0]
      $newS &= ".*" & $aS[$i]
  Next
   $newS &= ".*"
   ConsoleWrite($newS & @CRLF)

   return StringRegExp($sSearchString,"(" & $newS & ")") 
  
EndFunc; ==> _StringInStrRandom

Link to comment
Share on other sites

still not sure how to capture those instances when theres characters if there are middle characters between my string match..

bah!

(this one only does before and after)

"SELECT AssetTag,Model,SerialNumber FROM aInventoryInfo WHERE SerialNumber LIKE '%" & $serial & "%'"
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...