简体   繁体   English

使用正则表达式提取子字符串

[英]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. 我想从每一行中提取子字符串“ AMERICANS”,“ APAC”,“ EAME”。 I am hence looking for a Regex which can do this for me. 因此,我正在寻找可以为我做到这一点的正则表达式。 I am not very good at Regex. 我不太擅长Regex。 Can anyone please help me with this ? 有人可以帮我吗? I need a Java Regex 我需要一个Java正则表达式

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 DEMO

i think you need to escape the backslash one more time in qregularexpression. 我认为您需要在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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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