Regex to remove certain words on Arduino

how do I remove letters in front of numbers on an Arduino, for example I have it written "test123" to become "123" then I also want the reverse "test123" to become "test" so later it will be like this

msg = test123;
if (msg == set){
Serial.print(msg); //it contains numbers
}else{}

msg == set

With c- strings, read about strtok(), and drop the separated werds into an array.
Then you can do whatever you want.with.enny.of.the.werds .

Do you just want to limit it to numbers? Tell more about how you actually want to filter your data.

To answer the question directly

^([a-zA-Z]+)([0-9]+)

This will look for a word of one or more (+) letters [a-zA-z] at the beginning (the caret) of the text followed by one or more (+) digits (`[0-9]. Anything following that will be ignored.

The result is grouped so you will e.g. get 'test' and '123'.

You can test here: https://regex101.com/

If it's the best way is another question.

I don't know how to implement it on arduino, it's different code
test serial available

what makes you think you will need REGEX?

Please explain what you want to achieve.

I want to retrieve the number from the text "test123" and I also want to be able to retrieve the text "test" but when I type test123f it will be considered incorrect

take the first 4 characters--> it is test
take the last 3 characters --> it is 123

But I assume you should describe what your really want to achieve.

How does substring know that the text is "test123" and take "test" but when it says "test123f" or "test" it thinks it is false?

you can test for f

or if the length of the second part isn't 3 characters long.

But again: WHAT do you want to achieve in your program?

Do you want to read a key (a variable) and a value from Serial and use the new numeric value in the program for that variable?

When I type "test123" the result "123" appears
Cuplikan layar pada 2024-01-23 11-37-17

When I type "test" it should be false and when I type "test123f" it should be false
Cuplikan layar pada 2024-01-23 11-33-34

.
if you can't explain your real usecase and can't answer my questions it makes no sense for me to continue.
Good luck with your project - I'm out.

char gstring[] = {"thx1138orc"};
void setup() {
  Serial.begin(9600);
  for (int i = 0; i < strlen(gstring); i++) {
    if (gstring[i] > 47 && gstring[i] < 58)
      Serial.print(gstring[i]);
  }
}
void loop() {}

Result

1138

It doesn't, unless you are always removing a fixed word length. The test case that you keep presenting is not clear enough. What do you actually need to do?

I want to make a word in the serial monitor to save data, when I type test123 or test321 then the numbers 123 and 321 will be saved because what we read is test but when I just type test, test123f, testh123 then in the serial monitor there will be an error written

Why would you repeat yourself so many times without actually saying what you are trying to do?

It's clear that you are working on a project that us plebeians do not have clearance to understand. Best of luck.

I usually use regex in other code to do this but I haven't figured out on arduino to implement that

Arduino doesn't support regex natively. As others have been trying to tell you, there are better and cheaper ways to achieve your goals, should you decide to actually say what you are trying to do.