0

I'm new to Regex and I'm trying to extract a path from a string found inside a file. But there are many strings that could match the regex I managed to come up with so I came to the conclusion I need to apply the string only if it's enclosed between static strings.

The file looks like this:

14:58:15 [LC] AKF = 0-65535
14:58:15 [THR] CPU 02 : Engine (AFK)
14:58:15 [QA] Result Path : [/some/linux/path/Results/Test_2013_09_12_14_58_15]
14:58:15 [THR] Starting Listener
14:58:15 [THR] Starting Listener

What I'm not sure is if with a regex I could create a pattern that includes the enclosing strings ("[QA] Result Path : " and "]") or if I need to code that logic?

I'm using OpenJDK 1.7.

1
  • have you tried something? Commented Nov 23, 2013 at 10:04

2 Answers 2

1

You seem to think that you can use only the pattern matching characters in your regex. You can include literals:

  abc.*def

Will search for "abc" followed by any number of any characters followed by "def". If the characters you want to search for are "special", for example a . or a ] then you will need to escape them with a .

Sign up to request clarification or add additional context in comments.

Comments

0
\[(.*?)\].*?\[(.*?)\]$

It should capture contents of both brackets.

$ is "end of string", you can omit it if it's not important.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.