正则表达式选择特定文本之前和之前的所有内容 [英] Regular Expression to select everything before and up to a particular text
本文介绍了正则表达式选择特定文本之前和之前的所有内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用正则表达式来查找字符串的一部分并选择该字符串之前的所有内容.例如,如果我的字符串是 this/is/just.some/test.txt/some/other
,我想搜索 .txt
,当我找到它时选择.txt
之前的所有内容.
I am trying to use a regular expression to find a part of a string and select everything up to that string. So for example if my string is this/is/just.some/test.txt/some/other
, I want to search for .txt
and when I find it select everything before and up to .txt
.
推荐答案
执行以下正则表达式后,您的答案在第一次捕获中.
After executing the below regex, your answer is in the first capture.
/^(.*?)\.txt/
这篇关于正则表达式选择特定文本之前和之前的所有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文