Macro language "any digit" "any number"

Dear all,
I wrote this macro line:

imageToSelectString1 = substring(N0, indexOf(N0,“Position”), lastIndexOf(N0," “+number+” "));

but it does not work obviously because I did not defined “number”.

Instead of number I would like to write something to indicate that any number is accepted in that position, so the macro returns always the Position plus the number.


Probably you will need to use regular expressions:

matches(string, regex)
Returns true if string matches the specified regular expression. Can be replaced with string.matches(regex) in ImageJ 1.52t or later. See also: startsWith, endsWith, indexOf, replace.


not useful at all sorry, must be more complex than that.

matches() is absolutely what you want. For example,

res1 = matches("has no number", ".*[0-9]+.*");
res2 = matches("has 1 number", ".*[0-9]+.*");

Prints 0 and then 1.

As a side note, this is a place where people volunteer their time to help other people; responding to that with “not useful at all”, especially when it was the correct answer for the problem, is very rude!


Many thanks for your help. And I agree with all your comments.
Best regards,