Jump to content

StringRegExp - I cracked it... except i didn't.


Recommended Posts

So after my overcomplicated stringregexp funciong worked i decided to make it less complicated.

and so i did.

I went from

Func _Stringifier($Link)
Local $Counter
Local $Feedback
Local $ArraySize
Local $Array[2]
Local $CutValue
Local $String

;~ $Link = "http://www.stanceworks.com/wp-content/themes/saviour/images/graphics/stanceworks-twitter.png"
$Pattern = "(/*.)?"


$Array = StringRegExp($Link, $Pattern, 3)
;~ _ArrayDisplay($Array)

$ArraySize = (UBound($Array) - 1)

;~ MsgBox("","",$ArraySize )
For $Counter = $ArraySize To 0 Step -1
$Feedback = StringInStr($Array[$Counter], "/")
;~ ConsoleWrite("!" & $Counter & "-" & $Array[$Counter] & ": " & $Feedback & @CRLF)
If $Feedback = 1 Then ExitLoop
Next

;~ MsgBox("","",$Feedback)
;~ MsgBox("","",$Counter)

$CutValue = $ArraySize - $Counter

;~ MsgBox("","",$CutValue)
$String = StringRight($Link, $CutValue)
;~ MsgBox("","",$String)
Return $String
EndFunc ;==>_Stringifier

to

Func _Stringifier($Link)
Local $Pattern
Local $Array
Local $String

;~ $Link = "http://www.stanceworks.com/wp-content/themes/saviour/images/graphics/stanceworks-twitter.png"

;~ MsgBox("", "", $Link)
$Pattern = "w*b.jpg"
$Array = StringRegExp($Link, $Pattern, 1)

If $String = 1 Then
$Pattern = "w*b.png"
$String = StringRegExp($Link, $Pattern, 1)
Else
ConsoleWrite("File .jpg" & @CRLF)
EndIf

If $String = 1 Then
ConsoleWrite("File not jpg/png" & @CRLF)
Else
ConsoleWrite("File .png" & @CRLF)
EndIf

For $i = 0 To UBound($Array) - 1
;~ MsgBox("", "", "String: " & $Array[$i] & @CRLF & "Ubound: " & UBound($Array) - 1 & @CRLF & "$i: " & $i)
$String = $Array[$i]
Next

Return $String
EndFunc ;==>_Stringifier

So if i fix the pattern i can remove alot of stuff.

the pattern w*b.jpg worked for some time, except that it is also stopping on dashes ( - )

How can i add that to the pattern?

Like look for word but also dashes ? [w -]?

Also, how can i get it to search for .jpg or .png ?

I tried [(.jpg)(.png)] but i didn't get this to work

Edit:

Can i use the "|" to do this?

.jpg|,png ? or (.jpg|.png)?

Am i even close?

Edited by Maffe811

[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

Link to comment
Share on other sites

You could use [w-]+ but why bother for what you are testing?

Unless I misunderstood the problem; all you want to know is if it's either jpg or png

If StringRegExp($s_Test, "(?i).jpg|.png") Then
ConsoleWrite("File is type: " & StringRegExpReplace($s_Test, ".+.(.+)b", "$1") & @CRLF)
Else
ConsoleWrite("File is not of type jpg or png" & @CRLF)
EndIf

You should also take a closer look at what the flags do. You don't need a flag at all (or use 0) to test for True and False.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

you misunderstood :ermm:

What i want is this:

to become this:

accuair-stanceworks-avila-car-show-title.jpg

But currently it crashes with dashes -

so i only get:

title.jpg

and some are .jpg and some are .png

So the pattern would be find whats between .jpg/png and a slash.

[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

Link to comment
Share on other sites

.+/(.+.png|.+.jpg).*

You could also use an SRE replace to get the filename.

$s_Name = StringRegExpReplace($s_Str, ".+?/(.+.)(png|jpg).*, "$1$2")

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

.+/(.+.png|.+.jpg).*

This works perfectly!

But, would you care to explain how it works so i can see if i can actually learn this? :)

You could also use an SRE replace to get the filename.

$s_Name = StringRegExpReplace($s_Str, ".+?/(.+.)(png|jpg).*, "$1$2")

I belive you missed a " at the end of the pattern, so i added that.

But it removes http, but i have no idea on how to fix it.

[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

Link to comment
Share on other sites

To fix the srer just remove the "?"

The regexp matches everything up to the last "/" then captures everything after that as long as it ends in png or jpg,

Tip: Add "(?i) to the front of bothe the sre and the srer for safety sakes since the odd idiot uses caps in extensions.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

The regexp matches everything up to the last "/" then captures everything after that as long as it ends in png or jpg,

So .+/ means everything before a slash

(.+.png|.+jpg) means everything before .png.jpg, but after all the slashes? (This is what it returns, is that cause its in parentheses?)

.* is just to include anything else behind that ?

Tip: Add "(?i) to the front of bothe the sre and the srer for safety sakes since the odd idiot uses caps in extensions.

Okay, thanks!

[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

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