Jump to content
Sign in to follow this  

How to put wildcard characters in a string?

Recommended Posts


So im making a script that organizes TV shows. i have figured most of it out but im trying to find the portion of the title that contains the Season number and Episode number. (ie S01E13)

is there and easy way to search for the "S" and "E" in a string with any 2 random numbers in between them and after the "E"?


here is what i tried just as a very wild guess:

Func FindSeasonEpisode($FileName)
    $result = StringInStr($FileName, "S**E**")
    ConsoleWrite($result & @CRLF)

Share this post

Link to post
Share on other sites

Please have a look at StringRegExp.

My UDFs and Tutorials:


Active Directory (NEW 2017-04-18 - Version - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version - Download - General Help & Support

ADO - Wiki


Share this post

Link to post
Share on other sites

Func FindSeasonEpisode($FileName)    
  $result = StringRegExp ($FileName, "S\d\dE\d\d",0);   
  ConsoleWrite($result & @CRLF)

Try this for For S01E13 d accepts any digit. The helpfile has a detailed list of options you could use

Edited by tester123

Share this post

Link to post
Share on other sites

to be completely honest water, i would like to use stringregexp but i cant figure it out for the life of me.
if i had an example of how i would use it in this situation then i could probably mess with it enough to do more elaborate things but for now, tester123's solution works for me.
if you dont mind water, i would really like to see how i would use that function in my situation. if its not too much of a hassle.


@tester123 ty ty. this is what i was looking for :)


EDIT: tried the d but im getting a 0 for my results with StringInStr. when i do StringRegExp with the d's i get a 1 which is a match but how do i get the position like i do with StringInStr??

Edited by Kidney

Share this post

Link to post
Share on other sites

AH HA! i got it! lol

Func FindSeasonEpisode($FileName)
    $result = StringRegExp($FileName, "S\d\dE\d\d", 1)
    ConsoleWrite("StringRegExp " & $result[0] & @CRLF)
    Return $result[0]

changed the mode to 1. but im not sure why it writes it to an array with only one entry..... explain anyone??

Share this post

Link to post
Share on other sites

Perhaps it is easier to use StringRegExpReplace to do, depending on your task.

$string = 'S01E13 Some episode'
$var = FindSeasonEpisode($string)
MsgBox(0, '$var', $var)

Func FindSeasonEpisode($FileName)
    Return StringRegExpReplace($FileName, "\A\w(\d+)\w(\d+) (.*)", '\1-\2 \3')

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  

  • Similar Content

    • XinYoung
      By XinYoung
      Hello again,
      I'm trying to use the FileMove function to rename a bunch of text files.
      Some of the files have "_1" at the end of their name, for example, "File123_1.txt". I want to remove the "_1" so it would become "File123.txt".
      What I currently have...
              FileMove($sSource & "\*_1.txt", $sDestination & "\*.txt")
      But since I'm using a wildcard, it doesn't appear to be working. I think it's just replacing .txt with .txt. Am I going about this the wrong way? How can I use wildcards and still accomplish this?
      Any help is greatly appreciated ^__^
    • ur
      By ur
      I have date in the string format as "DD-MM-YYYY".
      I need to get yesterday's date from it.
      I tried converting this from _DateTimeFormat but not working.
      Is there any direct UDF available to get this.?
    • rkr
      By rkr
      Hi, i want to read a particular string from a text file using autoit. i wish to read it without explicitly opening the text file. the copied string should be then transferred to an excelbook (again, no need to explicitly open the excel book)... 

      with reference to my screenshot attached, my input to the  'script'' is going to be 0017-0008, and the script should copy the highlighted two lines from the input file to excel

    • cheeroke
      By cheeroke
      Hi all,
      I got this code and would like to be able to change Baud Rate and instead of sending character by character i would like to be able (if possible) to send whole string. But i don't know how to change it.
      I am taking input from file and processing whole line (this is done in FilesHandling.au3).
      To execute this i am just calling SendData("FileName", int) in "main" script.
      Any help very appreciated.
      #include <WinAPI.au3> #include <Array.au3> #include "FilesHandling.au3" ;init DLL function, we need handle to call the function $h = DllCall("Kernel32.dll", "hwnd", "CreateFile", "str", "\\.\COM19", "int", BitOR($GENERIC_READ,$GENERIC_WRITE), "int", 0, "ptr", 0, "int", $OPEN_EXISTING, "int", $FILE_ATTRIBUTE_NORMAL, "int", 0) $handle=$h[0] Func SendData($FileName, $LineNumber) ;string to be send $c = readFile($FileName, $LineNumber) $cLenght = StringLen($c) $aArray = StringSplit($c, "") ;_ArrayDisplay($aArray, "", Default, 64) For $i = 1 To $cLenght writeChar($handle, $aArray[$i], $cLenght) Next ;move to next line writeChar($handle, @CR,1) EndFunc ;write a single char func writeChar($handle,$c,) $stString = DLLStructCreate("char str") $lpNumberOfBytesWritten = 0 DllStructSetData($stString, 1, $c) $res = _WinAPI_WriteFile($handle, DllStructGetPtr($stString, "str"), 1,$lpNumberOfBytesWritten) if ($res<>true) then ConsoleWrite ( _WinAPI_GetLastErrorMessage() & @LF) EndIf EndFunc  
    • FroVN
      By FroVN
      Hi, i have a problem :" can't set the name of file with a special character like: \;/;";|;...  have anyway to short the StringInSrt and Stringreplace? i am using this code but too long
         if StringInStr($title,'\') or StringInStr($title,'/') or StringInStr($title,':') or StringInStr($title,'*') or StringInStr($title,'?') or StringInStr($title,'"') or StringInStr($title,'<') or StringInStr($title,'>') or StringInStr($title,'|') Then

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.