Jump to content

Bit Of RegEx help please


ChrisL
 Share

Recommended Posts

$Str1 = "/photo-selection/my-albums/1104042"
$Str2 = "/photo-selection/my-albums/shared-982502"

$regEx = "albums/(?:shared-)(\d+$)"

MsgBox(0,"",StringRegExpReplace($Str1,$RegEx,"albums/"))
MsgBox(0,"",StringRegExpReplace($Str2,$RegEx,"albums/"))

Can someone help with this, I need 1 RegEx to work with both strings, sometimes it contains "shared-" and sometimes not, I know there are other ways to do it but I think it should be possible to do with just StringRegExp

 

Thanks

Link to comment
Share on other sites

Hi.

if I get your task description right you basically need to cut off everything following the final "/" in your strings?

 

$Str1 = "/photo-selection/my-albums/1104042"
$Str2 = "/photo-selection/my-albums/shared-982502"

MsgBox(0, 'String Left String 1', StringLeft($Str1,StringInStr($Str1,"/",0,-1))) ; take the left part of any string including the last occurence of "/"
MsgBox(0, 'String Left String 2', StringLeft($Str2,StringInStr($Str2,"/",0,-1))) ; take the left part of any string including the last occurence of "/"

$RegEx="^(.*?/)(?:[^/]+)$"
MsgBox(0, 'RegEx String 1', StringRegExpReplace($Str1,$RegEx,"$1"))
MsgBox(0, 'RegEx String 2', StringRegExpReplace($Str2,$RegEx,"$1"))

 

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

No I can't do that because sometimes it maybe a completely different string, which is why I included the albums/ as part of the search term, sometimes it has shared- and sometimes it doesn't.

So basically if it doesn't contain /albums then leave it, if it contains album/shared-xxxxxxx then trim it, if it contains albums/xxxxxxx then trim it

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