1

I want to extract multiple strings from one string based on certain regex.

Example:

Input String :

20140909 Sample String 1 TRAINING COMPLETE useless string TRAINING COMPLETE useless string 2 TRAINING COMPLETE useless string 2 TRAINING COMPLETE 20120206 sample string 2 TRAINING COMPLETE

I want to extract the strings between the date string and TRAINING COMPLETE string.

Expected Output of Above String is following two strings

20140909 Sample String 1 TRAINING COMPLETE
20120206 Sample String 2 TRAINING COMPLETE

Regex I am using: (\d{8})(.*?)TRAINING COMPLETE But this gives only the first required string, I want all the required strings.

2
  • What language/tool are you using ? Commented Sep 10, 2014 at 13:26
  • if you are using php use preg_match_all Commented Sep 10, 2014 at 13:33

1 Answer 1

1

You need to use the global modifier g

Online Demo

/(\d{8})(.*?)TRAINING COMPLETE/g
  • g stands for g lobal. It matches all and not just on first match
Sign up to request clarification or add additional context in comments.

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.