English 中文(简体)
1. 定期表示与书面格式相匹配
原标题:Regular Expressions to match files with speecial format
  • 时间:2010-07-01 16:26:31
  •  标签:
  • grep

I have the following names of files: When x is a number (x could be number between 0 to 100)

fileX
fileXblabla
fileX.X
fileX.Xblabla

例如

fileX --> file1
fileXblabla --> file1blabla
fileX.X --> file5.3
fileX.Xblabla --> file2.9blabla

我的问题是,如何在目录下对以下各类档案进行匹配(用灯和定期表达方式或其他方式)

例如

 fileX

根据目录,我们希望获得所有档案,如档案1或档案2或档案3。

 fileXblabla

根据目录,我们希望获得所有档案,如档案1bla或档案2bla或档案3bla......。

 fileX.X

根据目录,我们希望获得所有档案,如档案1.1或档案2.1或档案3.1。

 fileX.Xblabla

我们希望获得所有档案,如:文件1.1bla或文件2.1bla或档案3.1。 .......file100.100bla

最佳回答

为此:

^file(100|[1-9]d|d)(.(100|[1-9]d|d))?(bla)*$
问题回答

以下区域评价组将符合所有4种模式:

file(d{1,3})(w*)(?:.(d{0,3})(w*))?

The X in fileX will be in back reference 1
The blabla in fileXblabla will be in back reference 2
The Y in fileX.Y will be in back reference 3
The blabla in fileX.Yblabla be in back reference 4.

如果你们需要更多的帮助,就添加一个意见。





相关问题
Really strange grep 2.5.1 bug in cat d reading long lines

Recently a peer and I discovered an interesting bug in GNU grep 2.5.1 in which standard input with lines greater than 200,000,000 characters causes grep to fail, even if the pattern is not in one of ...

grep a tab in UNIX

How do I grep tab ( ) in files on the Unix platform?

how to grep a variable in the shell program? [duplicate]

#!/bin/bash for ((var=0; var<20; var++)) do echo " Number is: $(grep Multiple_Frame = echo **$var** 20mrf.txt | wc -l)" >>statisic.txt done This shell program cannot produce correct ...

GREP - finding all occurrences of a string

I am tasked with white labeling an application so that it contains no references to our company, website, etc. The problem I am running into is that I have many different patterns to look for and ...

Grep doesn t work correctly with .as files

Here s the statement I m running: grep -i -H ConfigureControls *.as Note that I m forcing file names with the -H flag. What I get back is: } } trac} } this.chairControls.debug....

热门标签