开发者

searching backwards with regex

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 pr开发者_如何学Cobably will have to be a special case for line3 as I dont expect anything back.

I am using groovy for this regex.


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).


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜