首页 \ 问答 \ 正则表达式匹配行以空格开头,第一个字符不是数字(Regex match line starting with whitespace and first character is non-digit)

正则表达式匹配行以空格开头,第一个字符不是数字(Regex match line starting with whitespace and first character is non-digit)

我试图创建一个正则表达式,它只匹配以空格开头的行,然后有1-4个非数字作为第一个字符,然后在数字后面至少有一个或多个空格。 此正则表达式的目的是在Notepad ++的“查找和替换”选项中使用它来删除所有不以空格开头的行,然后将一个数字作为行中的第一个字符。

我现在拥有的是允许我匹配以空白开头的行,并跟随一组数字和另一个空格。 但是,这些是我想保留的路线。 我如何修改以下正则表达式,以便它匹配除这些行之外的其他所有内容?

/^([\s]+\d[\s]|[\s]+\d\d[\s]|[\s]+\d\d\d[\s])/gm

这里是我们使用正则表达式的数据的一个例子。 正则表达式只能匹配不以1,2,49,50,99和100开头的行。请注意,以“第40位”和“2017/5/23/2017”开头的行应匹配。

                                                                      Page 1
          40th Marathon and 25th Marathon Relay
5/23/2017      USATF Certified Marathon (#RE98723UB)      Downtown/City, ST
Timing: Race Services    See our Calendar of Events at www.website.com
             Results questions: http://www.website.com/fixresults
=====================================================================================
                 **** FINAL RESULTS IN NETTIME ORDER ****
Place Div/Tot  Div   Halfway 22miles Guntime  Nettime Pace  Name   
===== ======== ===== ======= ======= =======  ======= ===== =======
    1   1/153  M0139 1:15:08 2:05:50 2:29:20   2:29:20  5:42 Eric
    2   2/153  M0139 1:15:07 2:06:29 2:29:56*  2:29:56  5:44 Bryan
Record 2:17:35 by Randy in 1986
   49   8/77   M4049 1:36:48 2:54:03 3:37:02   3:36:59  8:17 Joshua
   50  28/153  M0139 1:49:45 3:03:56 3:37:38#  3:37:22  8:18 Brian
# Under USATF OPEN guideline
   99   1/16   M6069 1:56:30 3:15:24 3:51:06   3:50:46  8:49 Paul
  100   3/35   F5059 1:50:06 3:11:37 3:51:03   3:50:47  8:49 Ashley
  101   4/35   F5059 1:55:26 3:16:37 3:56:03   3:55:57  9:14 Joan
* Under USATF Age-Group guideline
% For an Explanation of AgeGraded Percentages, See Here: http://www.website.com/agegrading

因此,如果我们在Notepad ++中使用正则表达式来查找匹配的字符串/行并替换(删除)它们,那么期望的最终结果如下(换句话说,下面的行不会匹配正则表达式):

    1   1/153  M0139 1:15:08 2:05:50 2:29:20   2:29:20  5:42 Eric
    2   2/153  M0139 1:15:07 2:06:29 2:29:56*  2:29:56  5:44 Bryan
   49   8/77   M4049 1:36:48 2:54:03 3:37:02   3:36:59  8:17 Joshua
   50  28/153  M0139 1:49:45 3:03:56 3:37:38#  3:37:22  8:18 Brian
   99   1/16   M6069 1:56:30 3:15:24 3:51:06   3:50:46  8:49 Paul
  100   3/35   F5059 1:50:06 3:11:37 3:51:03   3:50:47  8:49 Ashley
  101   4/35   F5059 1:55:26 3:16:37 3:56:03   3:55:57  9:14 Joan

任何援助将不胜感激。


I am trying to create a regex that will only match lines that start with whitespace, then have 1-4 non-digits as the first characters, and then at least one or more spaces after the digits. The purpose of this regex is to use it in the "Find and Replace" option of Notepad++ to remove any lines that do not start with space(s) and then have a number as the first character in the line.

What I have now is allowing me to match the lines that start with whitespace and are followed with a group of digits and another space. However, these are the lines I want to keep. How can I modify the following regex so that it will match everything else other than these lines?

/^([\s]+\d[\s]|[\s]+\d\d[\s]|[\s]+\d\d\d[\s])/gm

Here's an example of the data we're using the regex on. The regex should only match the lines that DO NOT start with 1, 2, 49, 50, 99 and 100. Note that the lines that start with "40th" and "5/23/2017" should match.

                                                                      Page 1
          40th Marathon and 25th Marathon Relay
5/23/2017      USATF Certified Marathon (#RE98723UB)      Downtown/City, ST
Timing: Race Services    See our Calendar of Events at www.website.com
             Results questions: http://www.website.com/fixresults
=====================================================================================
                 **** FINAL RESULTS IN NETTIME ORDER ****
Place Div/Tot  Div   Halfway 22miles Guntime  Nettime Pace  Name   
===== ======== ===== ======= ======= =======  ======= ===== =======
    1   1/153  M0139 1:15:08 2:05:50 2:29:20   2:29:20  5:42 Eric
    2   2/153  M0139 1:15:07 2:06:29 2:29:56*  2:29:56  5:44 Bryan
Record 2:17:35 by Randy in 1986
   49   8/77   M4049 1:36:48 2:54:03 3:37:02   3:36:59  8:17 Joshua
   50  28/153  M0139 1:49:45 3:03:56 3:37:38#  3:37:22  8:18 Brian
# Under USATF OPEN guideline
   99   1/16   M6069 1:56:30 3:15:24 3:51:06   3:50:46  8:49 Paul
  100   3/35   F5059 1:50:06 3:11:37 3:51:03   3:50:47  8:49 Ashley
  101   4/35   F5059 1:55:26 3:16:37 3:56:03   3:55:57  9:14 Joan
* Under USATF Age-Group guideline
% For an Explanation of AgeGraded Percentages, See Here: http://www.website.com/agegrading

So if we used the regex in Notepad++ to find the matching strings/lines and replace (delete) them, the desired end result would be as follows (in other words, the following lines would NOT match the regex):

    1   1/153  M0139 1:15:08 2:05:50 2:29:20   2:29:20  5:42 Eric
    2   2/153  M0139 1:15:07 2:06:29 2:29:56*  2:29:56  5:44 Bryan
   49   8/77   M4049 1:36:48 2:54:03 3:37:02   3:36:59  8:17 Joshua
   50  28/153  M0139 1:49:45 3:03:56 3:37:38#  3:37:22  8:18 Brian
   99   1/16   M6069 1:56:30 3:15:24 3:51:06   3:50:46  8:49 Paul
  100   3/35   F5059 1:50:06 3:11:37 3:51:03   3:50:47  8:49 Ashley
  101   4/35   F5059 1:55:26 3:16:37 3:56:03   3:55:57  9:14 Joan

Any assistance would be greatly appreciated.


原文:https://stackoverflow.com/questions/48955031
更新时间:2022-04-21 18:04

最满意答案

我不熟悉IntelliJ,但是,我看到有一个控制台调试工具 ,您可以在执行时访问变量值。 只需停止您想要的执行,并使用它来访问faces上下文并使用其名称获取托管bean:

  FacesContext context = FacesContext.getCurrentInstance();
  context.getApplication().evaluateExpressionGet(context, "#{" + beanName + "}", Object.class);

使用CDI时,您可以执行以下操作:

@Inject
private Bean bean;

得到了这个答案

问候。


I'm not familiar with IntelliJ, however, I saw there's a console debug tool, where you can access variable values while executing. Just stop the execution where you want and use it to access the faces context and get the managed bean using its name:

  FacesContext context = FacesContext.getCurrentInstance();
  context.getApplication().evaluateExpressionGet(context, "#{" + beanName + "}", Object.class);

When using CDI, you can do it like below:

@Inject
private Bean bean;

Got from this SO answer.

Regards.

相关问答

更多
  • 好的,现在我觉得有点傻:-( 我绕过了代理提供的上下文bean,没有使用getter / setter进行成员访问。 相反,我直接使用package-private字段来阻止代理提供正确的实例。 一旦我切换到getters / setter,它就开始按预期工作了。 Ok, now I feel kind of stupid :-( I was bypassing the contextual bean provided by the proxy by not-using getters/setters fo ...
  • 为什么它被称为会话bean,据我所知,它与会话无关,我可以通过在会话中存储pojo来达到同样的效果。 从旧的J2EE 1.3教程 : 什么是会话Bean? 会话bean表示J2EE服务器内的单个客户端。 要访问部署在服务器上的应用程序,客户端将调用会话bean的方法。 会话bean为其客户端执行工作,通过在服务器内部执行业务任务来避免客户端的复杂性。 顾名思义,会话bean类似于交互式会话。 会话bean不共享 - 它可能只有一个客户端,就像交互式会话可能只有一个用户一样。 就像交互式会话一样,会话bean ...
  • 我不熟悉IntelliJ,但是,我看到有一个控制台调试工具 ,您可以在执行时访问变量值。 只需停止您想要的执行,并使用它来访问faces上下文并使用其名称获取托管bean: FacesContext context = FacesContext.getCurrentInstance(); context.getApplication().evaluateExpressionGet(context, "#{" + beanName + "}", Object.class); 使用CDI时,您可以执行 ...
  • 发生这种情况是因为您已在BeanOne init方法中手动初始化了user对象。 依赖注入的目的是让一些容器为您创建对象的实例,因此您永远不应手动初始化对象。 因此,只需为此用户设置一个名称,它将在会话期间显示所有其他bean。 @PostConstruct public void init() { user.setUserName("TestName"); } This happens because you have manually initialized user object in BeanOn ...
  • 取决于你的意思: 在这些请求中访问@SessionScoped bean时显式控制同步 你是对的,可能有几个线程并行访问@SessionScoped bean。 所以一般来说你必须要注意线程的安全性。 是否需要显式控制同步(或根本不同步)取决于如何从不同线程使用或修改共享状态。 如果使用java.util.concurrent或java.util.concurrent.atomic类,则可以在没有单个synchronized语句的情况下实现完美的线程安全性。 但是,是的,你必须照顾线程安全。 Depends ...
  • 我发现我在一个控制器中有两个@PostConstruct。 奇怪的是,这个错误我只用beans.xml得到它。 如果你有两个注释,比如@PreDestroy @PostConstruct,那么你会发现错误。 I found that I have two @PostConstruct in one controller. The strange thing that this error I got it only with beans.xml. If you have two annotations li ...
  • 看起来你的测试不起作用: testModel object = model.TestModel@689a6064 New version : Version 2, Object : model.TestModel@61606aa6 因此,您更新的实例与链接到会话的实例不同(另一个请求不会重复使用我所说的相同会话) Looks like your test doesn't work: testModel object = model.TestModel@689a6064 New version : Vers ...
  • 在web.xml ,需要注释掉标记。 所以相应的部分看起来像: 60 true <-- Not be set locally -->
  • 您没有使用javax.faces.bean包中的 @SessionScoped声明bean,而是使用javax.enterprise.context包 。 这与javax.faces.bean包中的@ManagedBean不兼容。 然后,该bean将默认为请求范围,其行为类似于@RequestScoped 。 修复您的导入。 import javax.faces.bean.ManagedBean; import javax.faces.bean.SessionScoped; @ManagedBean @S ...
  • 我仍然没有答案,而是BalusC在此提到的另一个解决方案: 用户成功登录后,我只需将loginBean手动添加到sessionMap即可 FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("loginBean", this); 在WebFilter中,我使用了访问loginBean session.getAttribute("loginBean") 这是一个好的解决方案吗? 我的意思是......听起来像 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)