0

I am stumped working on a regular expression. So here is the sample text I am working with to run my regex on.

21;#ABC - A8 (ZYWX) DEF - S123 CODE ASD4 - PL_MN - 567aB - 987aL 6.8R WHHHA StackOverflow.file;42;#ABC_9876f_KIIIt_QW_blew34.files;43;#ABC-LKP RT00-44-33 [email protected];45;#Javax_P3_2345_123lE_451rP_Regex_Expression_Help.rewa;26;#GHJ - AQS 231-4_330-9 TIIIx Python JavaScript.text;

Here is the end result I am looking for after running the regex:

ABC - A8 (ZYWX) DEF - S123 CODE ASD4 - PL_MN - 567aB - 987aL 6.8R WHHHA StackOverflow  
ABC_9876f_KIIIt_QW_blew34  
ABC-LKP RT00-44-33 876aY@2200foo  
Javax_P3_2345_123lE_451rP_Regex_Expression_Help  
GHJ - AQS 231-4_330-9 TIIIx Python JavaScript   

A total of 5 matches.

The regular expression I have thus far is:

[A-Z][()\w\s@-]*

This regex isn't working though because the first line in my results ends up getting split in two pieces at the period. I am unable to come up with a solution as to how to fix this. I am fairly new to regex so any help would be appreciated. Thank you.

4
  • So the . after StackOverflow is a delimiter, but the . in 6.8R is not? Commented Jan 3, 2018 at 20:10
  • It looks like all your matches end with .<word>;, is that correct? Use a positive lookahead to match that. Commented Jan 3, 2018 at 20:12
  • Yes that is a correct. Commented Jan 3, 2018 at 20:12
  • You could just use regex split to split on ;42;# Commented Jan 3, 2018 at 20:24

1 Answer 1

1

It looks like each match ends with ., followed by a word, followed by ;. Use a positive lookahead to match a string followed by that.

[A-Z][()\w\s@\-.]*(?=\.\w+;)

DEMO

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

2 Comments

[A-Z][()\w\s@\-.]*(?=\.\w+;) <- errors out without escaped -
Yes. That works. Thank you for your help and such quick response. Looks like I have some learning to do on lookaheads.

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.