简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM