tags:

views:

95

answers:

2

I have the following different texts

line1: SELECT column1,
line2: column2,
line3: RTRIM(LTRIM(blah1)) || ' ' || RTRIM(LTRIM(blah3)),
line4: RTRIM(LTRIM(blah3)) || ' ' || RTRIM(LTRIM(some1)) outColumn,
line5: RTRIM(LTRIM(blah3)) || ' ' || RTRIM(LTRIM(some1)) something,
line6: somelast

Following is what I want to get out of each line basically want to start the regex search from end of string and keep going untill space. I can take out comma later on.

line1: column1
line2: column2
line3: <space> nothing found
line4: outColumn
line5: something
line6: somelast

basically I will be fine if I can start the regex from the end and walk towards first space.

There probably will have to be a special case for line3 as I dont expect anything back.

I am using groovy for this regex.

+1  A: 

Iterate over the lines and match each line against the regex:

(?i).*(column\w+).*

The word you're looking for is captured in group 1 ($1).

Bart Kiers
hmm I want to capture anyword...not just starting with 'column'. but I see the example was a bit misleading...
Omnipresent
A: 

I think you want:

(\w*)\s*,?$

Where match group one contains the first word at the end of the line.

Anchoring the expression to the end of the line basically is starting the regex from the end.

Tomalak