0
"^[\\s]*DISPLAY.*?(\".*?\").*?\\."

I have the above regular expression. However i have a problem with it.

DISPLAY AC-YEAR LINE 2 POSITION 68 REVERSE.

This string isn't captured as it should.

DISPLAY "EATING.FOOD" LINE 13 POSITION 31 REVERSE.

This is captured successfully.

I cant figure how I should write the regular expression.

"^[\\s]*DISPLAY.*?(\".*?\")  *,?,??       .*?\\.

Putting quantifiers after the ) doesn't work. It doesn't even capture the group.

0

3 Answers 3

2

The regex needs a pair of quotes (") present after the DISPLAY word. That's why the first one doesn't work.

If you want the first non white space word after the DISPLAY (everything between DISPLAY and LINE this should work:

^[\\s]*DISPLAY\\s*?(\".*?\"|.*?)\\s*?LINE.*?\\.
Sign up to request clarification or add additional context in comments.

5 Comments

that worked! thank you very much .. However i dont want LINE to be in regular expression... It should end when it finds a dot . (\\.) but not in quotes.
so for this DISPLAY AC-YEAR LINE 2 POSITION 68 REVERSE. you need to match AC-YEAR LINE 2 POSITION 68 REVERSE but for DISPLAY "EATING.FOOD" LINE 13 POSITION 31 REVERSE. you need to match only EATING.FOOD ?
I need to match the whole stuff. Match from DISPlAY to the dot . this is dead easy but if dot is in quotes it should not be considered as the end of the expression!
It is clear that you want to match the entire line, but what do you want to capture?
nothing just all the display statements.. they are later procceced
0

The first string did not match the regex because (\".*?\") matches anything between start quot and end quot, whicxh is not in your string. I suggest you test your regex here http://www.regexplanet.com/simple/index.html

Comments

0

This should work to capture AC-YEAR and "EATING.FOOD", while matching the entire line:

^\\s*DISPLAY\\s(.*?)\\s.*\\.$

Note that the $ matches the end of the line, so the literal dot \\. will only be matched at the end.

If you want to capture everything after DISPLAY, this should do it:

^\\s*DISPLAY\\s(.*?)\\.$

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.