I need help with regex

Hello i need a small help with regex.
I got this text, #define TDD 0 // Values: 0 (FDD), 1(TDD)”

i used this regex : [#][d][e][f][i][n][e]\s.[T][D][D]\s.[\d]
but the result is : "#define TDD 0 // Values: 0 (FDD), 1" and i want #define TDD 0” as output.
Am i on the right track ?


“A ‘#define’ instruction followed by a space followed by one or more uppercase characters (or underscores) followed by a space followed by one or more numbers”

I’ve guessed what you’re trying to capture, but more specific:

/#define TDD \n{1,}/

“’#define TDD ’ followed by one or more numbers”

Note I don’t now what flavour of regex you’re using, or what specifically you want too match, so this could be slightly off.

[] is for groups (one of…), so like [ABC] matches A, B or C, the way you’ve used it is redundant ([d] is one of “d”, which is exactly the same as d)

The flavour of regex is Js.
I only need the first number that is followed by TDD.

So you only want the number, that’s it?

Yes, only the number.


Will just match the first number (1 or more number characters) in the string

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.