R.Vector
R.Vector

Reputation: 1719

REGEX : get a text in middle of string and number

The problem I am facing is that if I have this string:

STARTGAME grindurr 9 51 19 3 7 1 2 2 0

...I want to extract name grindurr from the middle. I tried this regex:

STARTGAME\t.*\t[^\d]

...but it didn't work. :( Can anyone tell me what I'm doing wrong?

Upvotes: 0

Views: 3480

Answers (2)

Joey
Joey

Reputation: 354566

STARTGAME\s+(.*?)\s+\d

might work. The result is then in the first capturing group. You can remove the need for the capturing group by using lookaround, but I don't know the exact capabilities by that regex engine, so above is probably the safest way.

Upvotes: 4

alex
alex

Reputation: 490263

You can use...

STARTGAME\s+(.*?)\s+\d+

That should have the word between STARTGAME and the first number.

Upvotes: 3

Related Questions