Ritesh
Ritesh

Reputation: 237

Extract Sub string using Regular Expressions

I have a column called path like below. I want to extract the sub strings 'AMERICANS','APAC','EAME' from each row. I am hence looking for a Regex which can do this for me. I am not very good at Regex. Can anyone please help me with this ? I need a Java Regex

Path

F:\Email Alias\AMERICIANS\Americas - Team
F:\Email Alias\AMERICIANS\Americas - Territory
F:\Email Alias\AMERICIANS\Americas- Market
F:\Email Alias\APAC\APAC - Market
F:\Email Alias\EAME\EAME - Team

Required:

AMERICANS
AMERICIANS
AMERICIANS
APAC
EAME

Thank You.

Upvotes: 0

Views: 70

Answers (1)

Avinash Raj
Avinash Raj

Reputation: 174696

The below regex would match the strings you want.

[^\\]+(?=\\[^\\]*$)

DEMO

i think you need to escape the backslash one more time in qregularexpression.

Regular Expression:

[^\\]+                   any character except: '\\' (1 or more
                         times)
(?=                      look ahead to see if there is:
  \\                       '\'
  [^\\]*                   any character except: '\\' (0 or more
                           times)
  $                        before an optional \n, and the end of
                           the string
)                        end of look-ahead

Upvotes: 1

Related Questions