Solved

RegexReplace For On-Premise PRO path

  • 14 February 2023
  • 2 replies
  • 49 views

Userlevel 1
Badge +4

Hi Community, 

I am trying to use the AIMMS RegexReplace function to trim the folder path and keep the data case name. It’s working fine locally but it’s not working when testing in the server.

My code looks like this:

        block ! Get the full path for the Active Case File
            _sp_ActiveCasePathName := FormatString("%s", CaseFileURL(CurrentCase));

            !Check for server vs local. Local path won't likely contain the string 'PRO:/PublicDta'
            !example server path: PRO:/PublicData/Cases/spot_fw

            _bp_IndicateLocalFileName := not (RegexSearch(_sp_ActiveCasePathName,         "PRO:\\\\PublicData"));

            ! Text example _sp_ActiveCaseName := "C:\GitHub\spot-fw\Model Folder\data\DataCase_C5AgeTest_Output.data"

            ! This Removes the structure 
            !local: C:\\Location_of_File\With general\ideas-of-how\afilesnamewouldbe\ 
            !in the server: pro:/PublicData/Cases/FW SPOT Testing/
            !before the actual file name

            if _bp_IndicateLocalFileName then
                _sp_ActiveCaseName := RegexReplace(_sp_ActiveCasePathName, "C\\:\\\\([\\-\\_\\ [:alnum:]]+\\\\)+", "");
            else
                _sp_ActiveCaseName := RegexReplace(_sp_ActiveCasePathName, "[Pp][Rr][Oo]\\:\\\\([\\-\\_\\ [:alnum:]]+\\\\)+", "");
            endif;


        endblock;

        block ! Get the full path for the Active Case File
            _sp_ActiveCasePathName := FormatString("%s", CaseFileURL(CurrentCase));
            !Check for server vs local. Local path won't likely contain the string 'PRO:/PublicDta'
            !example server path: PRO:/PublicData/Cases/spot_fw
            _bp_IndicateLocalFileName := not (RegexSearch(_sp_ActiveCasePathName, "PRO:\\\\PublicData"));
            ! Text example _sp_ActiveCaseName := "C:\GitHub\spot-fw\Model Folder\data\DataCase_C5AgeTest_Output.data"
            ! This Removes the structure 
            !local: C:\\Location_of_File\With general\ideas-of-how\afilesnamewouldbe\ 
            !in the server: pro:/PublicData/Cases/FW SPOT Testing/
            !before the actual file name
            if _bp_IndicateLocalFileName then
                _sp_ActiveCaseName := RegexReplace(_sp_ActiveCasePathName, "C\\:\\\\([\\-\\_\\ [:alnum:]]+\\\\)+", "");
            else
                _sp_ActiveCaseName := RegexReplace(_sp_ActiveCasePathName, "[Pp][Rr][Oo]\\:\\\\([\\-\\_\\ [:alnum:]]+\\\\)+", "");
            endif;
        endblock;

 

Any ideas/help on what might be going wrong with the server file structure?

 

Thanks in advance!

icon

Best answer by MarcelRoelofs 16 February 2023, 10:07

View original

2 replies

Userlevel 1
Badge +4

Hi Marcel, 

Thanks for the follow-up. We did try using forward slashes but that didn’t do the trick either. Seems like we are missing something to capture the server file strucutre usign regex.

Any other advise for regex or would you recommend just switching to the findstring/substring method?

Thank you!

 

Best, 

Diego

Userlevel 4
Badge +5

Hi @Diego Perez-Urruti 

Well, the first thing I noticed is some confusion about how pro: paths are written. In your comment you use forward slashes, but your regular expressions use backward slashes. The documentation mentions forward slashes, so this may be the cause of your problems.

Alternatively, you could just use FindNthString to find the last forward/backward slash, and take the substring starting one position to the right.to find the case name.

Reply


Didn't find what you were looking for? Try searching on our documentation pages:

AIMMS Developer & PRO | AIMMS How-To | AIMMS SC Navigator