Jump to content
SirAlonne

Retrieve sequence number of a string from right hand side with Regular Expressions

Recommended Posts

Hi!
I've been experimenting for a while with this but it seems I stuck in a wall or missing something..:sweating:
So let's say i have a string and I want an unknown length sequence number (in this case the 11) so I used:

Local $String = "john.wick.cv. 2019.russian 666_roulette 11.pdf"
StringRegExpReplace($String, "^.*\h|D", "", Default)
; This retrieved "11"

BUT if the filename changes "john.wick.cv.2019.russian 666_roulette11.pdf"  because a retarted user accidentally forgot to put space before the number, then the previous method does not works.. Is there a way to retrieve the sequence with regular expressions starting from right hand side?


To summarize it more briefly:

  • The filename could be anything
  • The sequence number always at the end of the filename followed by the dot and the extension
  • The sequence number could be any length (\d+)
  • The filetype is a set of extensions (.pdf .psd .ai .blend)
Edited by SirAlonne

Share this post


Link to post
Share on other sites

Nice mikell, but I would change to  ".*\D(\d+)\..*" in case there is a number in the extension (ex.au3)

Share this post


Link to post
Share on other sites

oh, we can complicate things

Local $String = "john.wick.cv. 2019.russian 666_roulette5711.pdf"

msgbox(0, '' , stringreverse(number(stringreverse(stringmid($String , 1 , stringinstr($String , "." , 0 , -1) - 1)))))

 


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites
6 hours ago, Nine said:

in case there is a number in the extension

Absolutely right... but as usual I strictly followed the requirements mentioned in post #1  :idiot:

8 hours ago, SirAlonne said:

The filetype is a set of extensions (.pdf .psd .ai .blend)

 

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.

×
×
  • Create New...