如何解析文本后的特定单词?
我想要解析的文本始终采用以下模式:
“Your $22.12 transaction with Amazon.com”
我想解析“transaction with”之后的所有文本,这将是公司/商店的名称。
有人可以帮忙吗? 太感谢了!
这个问题在这里没有足够相关的答案:Javascript Regexp - 匹配特定短语后的字符 该问题是关于匹配固定、精确、常量短语后的字符。此问题中的短语包含变化的子字符串($金额)。 答案除了如何获取文本后的字符之外,还应该解释如何将美元金额与正则表达式匹配.
The text I would like to parse always comes in the following pattern:
"Your $22.12 transaction with Amazon.com"
I would like to parse all text after "transaction with " which would be the name of company/store.
Can anybody help with this?
Thank you so much!
This question does not have a relevant enough answer here : Javascript Regexp - Match Characters after a certain phrase That question is about matching characters after a fixed, exact, constant phrase. The phrase in this question contains a substring (the $ amount) that varies. An answer should explain, in addition to how to get characters after text, how to match a dollar money amount with RegEx.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此正则表达式可能有效:
只需创建一个与开头短语匹配的正则表达式,后跟
(.*)
。\d
匹配 0 到 9 之间的任何数字字符。加号
+
匹配其前面的 1 个或多个字符。\d+
匹配 1 个或多个数字。{2}
与某物中的 2 个完全匹配。\d{2}
匹配 2 位数字。.
匹配任何字符。*
匹配其前面的零个或多个内容。因此正则表达式.*
贪婪地匹配任意数量的任意字符。将.*
括在括号中会创建一个捕获组,使您可以在运行正则表达式后获取匹配的文本。This Regular Expression may work:
Just make a regex that matches the beginning phrase followed by
(.*)
.\d
matches any digit character from 0 to 9.The plus sign
+
matches 1 or more of what precedes it.\d+
matches 1 or more digits.{2}
matches exactly 2 of something.\d{2}
matches 2 digits..
matches any character.*
matches zero or more of what comes before it. So Regex.*
matches any number of any character, greedily. Wrapping.*
in parentheses creates a capture group that lets you get the matched text after running the regex on it.