Jump to content
Sign in to follow this  
Kidney

How to put wildcard characters in a string?

Recommended Posts

Kidney

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)
EndFunc

Share this post


Link to post
Share on other sites
water

Please have a look at StringRegExp.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
tester123

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

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
Kidney

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
Kidney

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]
EndFunc

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
MHz

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')
EndFunc

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

    • nooneclose
      By nooneclose
      I need help turning this string "20180913221626" into a formatted time string.
      I need to go from this: 20180913221626
      to this: 09/13/2018 10:16 PM
      I do not always know what the date will be so I can not just use a variable I need to actually convert/format. 
      I did see an older post in the forms that was basically the same question only the other guy did not post the working code and I can not figure out how to use _AD_GetObjectProperties properly to get what I want. 
      As always any help would be appreciated. 
      Here is the code I use to find the date, but it always gives me the unformatted version. 
      ;retrieve the items object $oItem = $oOutlook.Session.GetItemFromID($aItems[1][0], Default) $oItem.GetInspector $eSentOn = $oItem.SentOn ; When was the email sent? MsgBox("", "Sent On of the email", $eSentOn) ;******************************************************************************* ; Formats the date and time from the email ;******************************************************************************* ;Local $fDatenTime = _DateTimeFormat($eSentOn, 1) ;MsgBox("", "Formatted email time", $fDatenTime) $aProperties = _AD_GetObjectProperties($eSentOn) _ArrayDisplay($aProperties, "Did the conversion work?")  
    • Miliardsto
      By Miliardsto
      I got that func
      Func makeHelpImgGUI($title,$width,$height,$img) $img = GUICtrlCreatePic("",20,40,$width,$height) _ResourceSetImageToCtrl($img, "HERE") EndFunc and I call this func like that
      makeHelpImgGUI("Image",1190, 800,$SETTINGS_JPG)  
      so what is the problem in the parameter where is - "HERE" I need value of img but passed as string
      so $img = $SETTINGS_JPG and how make it "SETTINGS_JPG"
       
      I tried something like that but not work
      Func makeHelpImgGUI($title,$width,$height,$img) $name_str = String($img) $name_str = StringTrimLeft ($name_str, 1 ) $img = GUICtrlCreatePic("",20,40,$width,$height) _ResourceSetImageToCtrl($img, $name_str) EndFunc  
    • liagason
      By liagason
      Hello everyone,
      How can I display in ascending  sequence some numbers stored in a string variable?
      $str = "18,03,48,23" MsgBox(0,"test",$str) I would like it to display "03,18,23,48"
    • Rskm
      By Rskm
      Hi, I have the following line in a text file 'input.txt'. I know the line number - say '6'. I wish to replace the text 'WWW' in the below line with a random number (I can generate that with random()).
      WERIS  WWWJP   3.83  8.330  1.000                1097.RAXX 
      The WWW is a 3 digit integer (could be any number between 0 to 999), I can use stringtrimleft and get the numerical value of WWW in this file
      so, basically, I know the string to replace (ie; WWW stored in a variable), I know the line number to work on and the file location/name and the replacement variable (through random()). My requirement is to fill that 3 spaces with my random number (which Is a integer between 1 and 999)
      please put ur suggestions
       
    • nacerbaaziz
      By nacerbaaziz
      Hello Members of this best Forum
      i have a question please
      for example if i have a long string
      and i want to extract a text between two tag
      what i can do to make that?
      note :
      i know that there is a
      StringRegExp function
      it's do that work
      but it result is be as an array
      i want the result to be a string
      is there any function on autoit can do that?
      Thanks in advance.
×