简体   繁体   English

尝试将行与正则表达式匹配

[英]Trying to match line with regular expression

I am trying to match the following line: 我正在尝试匹配以下行:

801. Our origination charge (Includes Originat ion Point (s) %  or $ ) (f rom GFE #1)$ 1,169.00

I have created this regular expression: 我创建了这个正则表达式:

.*801\\..*\\(f\\s?rom.*$\\s?(.*)

What this should do is: 这应该做的是:

  1. Match anything up until 801. 匹配直到801的所有内容。
  2. Match anything until(f\\s?rom 匹配任何东西,直到(f \\ s?rom
  3. Match anything until $ 匹配任何东西,直到$
  4. Optional space 可选空间
  5. Match the rest of line line 匹配其余的线

The way I believe this breaks my string down is like so: 我相信这会破坏我的思路,就像这样:

  1. 801. 801。
  2. Our origination charge (Includes Originat ion Point (s) % or $ ) 我们的始发费(包括始发点%或$)
  3. (f rom GRE #1 (从GRE#1
  4. (nothing) (没有)
  5. 1,169.00 1,169.00

However this is not the case. 然而,这种情况并非如此。 My regular expression does not match this string. 我的正则表达式与此字符串不匹配。 Any ideas why? 有什么想法吗?

Escape your dollar sign $ . 转义您的美元符号$ It's the end-of-line anchor . 这是行尾

.*801\..*\(f\s?rom.*\$\s?(.*)
.*801\..*\(f\s?rom.*\$\s?.*

Escape the $ character. 转义$字符。 And remove the brackets in the end.This regex exactly matches the string. 并删除最后的括号。此正则表达式与字符串完全匹配。

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

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