Pipeline runtime boost

Hello, I am new to the ci/cd pipeline related things. I want to enhance the speed of my pipeline.
I split my app to different jobs and those only runs if there is any change in the files.
only:
changes:
- src/xy/*.java

and I want to add this too:

only:
changes:
- src/xy/*.java
variables:
- $CI_COMMIT_MESSAGE =~ /any text/

but it does not trigger the job if I put the exact string in to my commit msg, but if I delete the changes part it works fine. How can I combine these options ?