Forum Discussion

AAB's avatar
AAB
Regular Contributor
3 years ago
Solved

ReadyAPI- Regex - delete numbers doesn't work

Hi all,

 

In my previous post I was looking for a way to run all teststeps with a code that adds a dateTime.

 

This ticket is to ask how to use Regex in ReadyAPI as this code isn't working:

 

 

 

filenameWithoutExtension.replaceAll("^[\\d]+", "")

 

 

 

So with this regex I want to ask the code to delete all numbers in the name of "filenameWithoutExtension" and replace it with something empty. That "something empty" is something I found on the internet, but I don't think actually that I would need that...right?

But nevertheless, it doesn't work.

 

Can someone help me with this please? or find another way to delete the date that is already present?

I've tried to find a regex with the help of this site:  https://regex101.com/

but that doesn't work neither. Maybe I'm using it wrongly. And of course looked on Stack overflow and a bunch of other forums but none of the description they gave can make ReadyAPI happy.

 

Thanks in advance,

AAB

8 Replies

  • richie's avatar
    richie
    Community Hero
    Hey AAB,

    Looking at your regex, it looks like it would match a date pattern and i use regex101 allthe time so i dont think the problem is there.

    This is a guess by me, but i suspect the issue is probably related to your filename variable. I might be able to help fix it, but my coding is nowhere near as good as the groovy experts on here. Either way i'd suggest publishing all your groovy so people can see how youve defined your filename variable along with the logs of exactly what is happening when you execute your current code.

    Ta

    Rich
    • AAB's avatar
      AAB
      Regular Contributor

      Hello richie 

      Thanks for your response. The original groovy is in the previous ticket. Not to overload all tickets with the same code, I thought it would be allright just to put the link of the previous ticket in here?

       

       

      Cheers,

      AAB

      • richie's avatar
        richie
        Community Hero

        Hey AAB 

         

        my bad - I didn't notice the link.  This replaceAll code works fine on normal parameters stored in the project cos I've used it loads and the regex is correct.

         

        HOWEVER - you're working with filenames arent you?

         

        I take it the log.info filenameWithoutExtension in your code works, right?

         

        the groovy experts (like nmrao, @aaronpliu  etc.) would know better than I - but I'm wondering if you actually explicitly pass the value into a property BEFORE you use the regex to remove the date whether that would work?

         

        ta

         

        Rich

    • AAB's avatar
      AAB
      Regular Contributor

      Hello nmrao Thank you for your answer.

       

      Indeed, this works! Thanks

       

      Kind regards,

      AAB

      • AAB's avatar
        AAB
        Regular Contributor

        I did found a way however to execute this, but ReadyAPI is crying over it.

        When I saved the properties on TestCase level in encodebase64, my xml file became far more bigger with a total of 134.45kb or so. I was astonished because a normal project would not exceed a 50kb I think? In composite projects this could be different, I don't know.

         

        Also, I had weird reactions from ReadyAPI UI like autoselecting teststeps and cases whenever I moved my mouse, and when I wanted to close ReadyAPI nothing happend. And when I minimized and maximized the UI I had a black screen with the close button and the frame.  I needed to open my taskmanager to kill it.

        So I need to re-look at the whole thing and find a better way to work with encodebase64 files! ðŸ˜°ðŸ˜«

        richie   nmrao   thanks for you help nevertheless!

         

        Kind regards,

        AAB

  • nmrao's avatar
    nmrao
    Champion Level 3
    What is the input value before replacement and expected value afterwards?